-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Add flatc '--cpp_std' switch #5656
Conversation
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.
Nice, this will allow us to start generating more modern code.
include/flatbuffers/flatc.h
Outdated
// There is no way to notify about an error from a code-generator | ||
// except `assert` call. | ||
// TODO: re-design interface to code generators. | ||
static void Warn(const std::string &warn); |
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.
If these are static, why aren't they simple extern functions?
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.
They should be extern functions, I will fix it.
The compilers have a non-extensible interface:
flatbuffers/include/flatbuffers/flatc.h
Lines 34 to 40 in eddebec
struct Generator { | |
typedef bool (*GenerateFn)(const flatbuffers::Parser &parser, | |
const std::string &path, | |
const std::string &file_name); | |
typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser, | |
const std::string &path, | |
const std::string &file_name); |
I've tried to replace the pack of args (parser, path, file_name) by reference to struct or class object with additional logging methods but refused due to too big changes in the code.
@@ -627,12 +627,6 @@ CheckedError Parser::ParseType(Type &type) { | |||
"length of fixed-length array must be positive and fit to " | |||
"uint16_t type"); | |||
} | |||
// Check if enum arrays are used in C++ without specifying --scoped-enums |
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.
Why is it better to do this in the code generator?
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.
- When other langs will support arrays this check will block
flatc
. - The
g_only_fixed_enums
flag in idl_gen_cpp is a more general flag. It can be set even if--scoped-enums
is inactive (C++11 unscoped enum with explicit underlying type).
There are CI errors: "src\idl_gen_cpp.cpp(2992): warning C4482: nonstandard extension used: enum 'flatbuffers::cpp::CppStandard' used in qualified name [C:\projects\flatbuffers\flatc.vcxproj]" It may well be that C++11 cannot be the default for the checked-in generated code, because of our VS2010 and Android CI. |
- Added 'flac --cpp_std legacy' for compatibility with old compilers (VS2010); - Added experimental switch 'flac --cpp_std c++17' for future development; - Added C++17 sandbox test_cpp17.cpp; - C++ code generator generates enums with explicit underlying type to avoid problems with the forward and backward schema compatibility; - Adjusted CMakeLists.txt, CI and generate code scripts to support of introduced '--cpp_std';
472c255
to
dfc4c9b
Compare
Fixed. PR was rebased to the master for compatibility with the latest changes in cpp-gen. If code is ok, we can merge it into the master after the next relsease. Maybe add more information about C++ compatibility options into |
Well, we can merge this now with C++0x as default, and then simply swap default after release? Sadly I guess there is no automatic way to identify those people that will need |
Really, this will be better. Travis failed in a strange way. On my repo with the same commit, Travis passed. |
The error appears to be: Let me know when you think this is ok to merge. |
7ec95ef
to
9132786
Compare
- Fix dependency declaration of grpctest target
9132786
to
d8a3f10
Compare
@aardappel GRPC-CI fixed, could you review the latest commit? Conditions:
Sequence-1 is invalid but could pass CI:
Sequence-2, CI failed with error:
Log with failed CI |
Thanks for this; when this is merged then I will submit a PR to add in the new table Create methods that we have discussed (I already sent PR 5674, which you can look at as a preview of what I will send). |
Thanks for finding what was happening with the CI. So are we able to create explicit dependencies in CMake such that this will always execute in the right order, such that this problem doesn't happen anymore? Or do we need to turn off parallel build? This PR still seems to default to C++11, I thought we were going to merge it with C++0x default, then change to C++11 after the next release? |
I think that all the problems with the dependencies were fixed. It will be better if the parallel compilation remains enabled. It speedups the CI and surfaces possible problems with test code. The flatc uses C++0x by default but all tests are generated with I have reverted P.S. Failure in Appveyor is unrelated. It failed in Rust tests. |
Ok, I will merge this then, thanks! |
@vglavnyy Given these changes, could you explain what steps I should take to make a PR with C++17 changes to the C++ generator? Thanks |
@dpacbach there are no restrictions or right ways, you can do as you wish. The |
* Add flatc '--cpp_std' switch and sandbox for C++17 code generator - Added 'flac --cpp_std legacy' for compatibility with old compilers (VS2010); - Added experimental switch 'flac --cpp_std c++17' for future development; - Added C++17 sandbox test_cpp17.cpp; - C++ code generator generates enums with explicit underlying type to avoid problems with the forward and backward schema compatibility; - Adjusted CMakeLists.txt, CI and generate code scripts to support of introduced '--cpp_std'; * Fix --cpp_std values: c++0x, c++11, c++17 * Add 'cpp::CppStandard' enum * Add testing engine into test_cpp17 * Rebase to upstream/master * Set default '--cpp-std C++0x' * Fix code generation (--cpp_std C++11) in CMakeLists.txt - Fix dependency declaration of grpctest target * Revert --cpp-std for the tests from explicit C++11 to flatc default value (C++0x)
Add flatc '--cpp_std' switch and sandbox for C++17 code generator:
This PR will change all already generated C++ code.
By default, generated enums will be declared with an explicit underlying type matched with a schema. For backward compatibility, a
flatc
switch--cpp_std legacy
was added.For future development an experimental switch
--cpp_std c++17
was added.Indirectly related issues: #5585, #5285, #5626, #5611.