Skip to content

Conversation

@jtdavis777
Copy link
Collaborator

Fixes #8557

@jtdavis777 jtdavis777 requested a review from aardappel December 14, 2025 02:12
@github-actions github-actions bot added c++ codegen Involving generating code from schema labels Dec 14, 2025
@jtdavis777
Copy link
Collaborator Author

the "better" way to fix this might be to SFINAE the StringType based template overload, but that seemed more ugly and this functions just fine.

@jtdavis777 jtdavis777 added the ready-for-merge This PR has been approved by a maintainer and is ready for merge by a code owner label Dec 20, 2025
@aardappel
Copy link
Collaborator

Yes, this doesn't seem a great solution since the problem is the overly generic template version that will just take any type.

Given that the users of these functions are mostly generated code, I wonder if we can't simply improve how this is called in generated code instead. Do they even need to be overloaded? What string types can this possibly be called with to warrant the overly generic template?

How does the original reporter call this to cause an error? Are they calling this function directly?

int KeyCompareWithValue(const char *_key) const {
return strcmp(key()->c_str(), _key);
}
int KeyCompareWithValue(char *_key) const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can we not just make this the only version? I believe const char * passed into a char * will work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a great suggestion. Will implement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char * passed to char * generally won't work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant to write it the other way around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew what you meant :) it just depends on if the argument match considers it close enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, no, this is the root of the issue. the original version is a const char* only -- the issue is that a const char* maps onto the templated version template<typename StringType> int KeyCompareWithValue(const StringType&)

So the two options are either

  1. providing an explicit overload for char*, or
  2. adding SFINAE conditions to the template deduction (which is a bit gross in C++11)

Copy link
Collaborator

@dbaileychess dbaileychess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a unit test for this. Find out where we do a call to KeyCompareWithValue in one of our tests and pass in both a const char* and char*.

@jtdavis777
Copy link
Collaborator Author

test added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema ready-for-merge This PR has been approved by a maintainer and is ready for merge by a code owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cpp] LookupByKey did not work for char* (works only for const char* or std::string)

3 participants