New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++] Fix unqualified namespaces #5374
[C++] Fix unqualified namespaces #5374
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
cf2b0ef
to
4b61f03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, thanks!
@@ -455,6 +455,17 @@ struct ServiceDef : public Definition { | |||
SymbolTable<RPCCall> calls; | |||
}; | |||
|
|||
struct FullyQualifiedType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use of this wrapper? If it was only useful during refactoring, please remove again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to enforce beginning with ::
as an invariant of the type, rather than having hidden requirements on a std::string
variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a LOT of strings thruout FlatBuffers that have expectations of the format contained in them (e.g. paths). I don't feel this case is special enough to warrant encoding the invariant in a class.
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64) /* end int */ \ | ||
TD(FLOAT, "float", float, float, float32, float, float32, f32) /* begin float */ \ | ||
TD(DOUBLE, "double", double, double, float64, double, float64, f64) /* end float/scalar */ | ||
TD(NONE, "", ::uint8_t, byte, byte, byte, uint8, u8) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to do it for these basic types as well? They already end in _t
which to me makes namespaces clashes very unlikely, and the clutter level is high.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don't know if it makes sense. Technically, the user could define uint8_t
etc types in their own namespace, which could break this, but this has a lower benefit than the other changes. I don't mind if it goes either way. Reverting the changes for these basic types seems fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that will be so rare, there is a benefit to readability to not have the ::
in this case.
@@ -0,0 +1,49 @@ | |||
include(CMakeParseArguments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for including comprehensive tests!
I would have liked it even better though if it had simply all been put in one test to curb the explosion of files/schemas/binaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the primary problem with putting them all in one test is the custom pointer/string as an attribute vs as a flag (the code handles it slightly differently), but it should be possible to combine it into two tests rather than eight.
@@ -29,6 +29,23 @@ | |||
#endif | |||
// clang-format on | |||
|
|||
// Ensure we are robust against adversarial namespaces: | |||
namespace MyGame { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this test things already sufficiently? What is covered in the adversarial tests dir that this doesn't do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this in later. The adversarial-namespaces tests are likely to fail for one reason, but this is likely to fail for many reasons.
This file is probably better, because it tests more possible failures. I think that this case doesn't test custom string and pointer types, whereas the adversarial-namespaces tests do include those tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test here is very cheap, the one in the adversarial tests dir are more expensive. If the ones here cover the most likely cases (of something that is already rare), I'd suggest removing the test dir. I know its not fun to remove things you already made, but if it helps maintainability going forward, I think its better to keep things simple.
@vglavnyy looks good to you? |
@googlebot I signed it |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
f381fd7
to
31f8799
Compare
3ba49dd
to
c4cd774
Compare
f116b80
to
f12cca8
Compare
This pull request is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days. |
Resolves #5308 .
There are tests in the first commit that don't pass until later commits. If necessary, I can rebase it to make the tests always pass.
Summary of changes:
flatbuffers
->::flatbuffers
std
->::std
flexbuffers
->::flexbuffers
std::swap(a, b)
->using ::std::swap; swap(a, b);
cpp_ptr_type
andcpp_str_type
are fully qualified, both when specified via--cpp-ptr-type
/--cpp-str-type
and via the attributescpp_ptr_type
/cpp_str_type
The last commits are a more questionable change:
intN_t
->::intN_t
. All of theuintN_t
s andintN_t
s.size_t
->::size_t
.