-
Notifications
You must be signed in to change notification settings - Fork 3.5k
flatbuffers.h: fix C++11 compilation (#8857) #8858
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
base: master
Are you sure you want to change the base?
Conversation
This constexpr officially works only with C++14 (assignment to lhs, 2 statements) and actually broke some C++11 compilers
|
would it not be better to rewrite these expressions to be constexpr 11 compatible? inline FLATBUFFERS_CONSTEXPR_CPP11 E operator | (E lhs, E rhs) {
return E(T(lhs) | T(rhs));
}
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator & (E lhs, E rhs) {
return E(T(lhs) & T(rhs));
}
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ^ (E lhs, E rhs) {
return E(T(lhs) ^ T(rhs));
}
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ~ (E lhs) {
return E(~T(lhs));
}
inline FLATBUFFERS_CONSTEXPR_CPP11 bool operator !(E rhs) {
return !bool(T(rhs));
}(just ran it through chatgpt, happy to be corrected if necessary :D ) |
I don't think it can be done, as constexpr cannot contain an assignment (lhs is assigned).
I doubled checked this (again), ChatGPT (5.2 Thinking) says its not possible. And lastly, the non-assignment operators (the one you got from ChatGPT) are already present, just above the assignment operators. So, this does not help. |
|
Got it! Sounds good. Figured it was worth a quick check. |
|
C++11 is very old. Do people still target that? |
|
I believe it is still the officially supported version of flatc, and this change doesn't hurt anything to go in |
| inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ^ (E lhs, E rhs){\ | ||
| return E(T(lhs) ^ T(rhs));\ | ||
| }\ | ||
| inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ~ (E lhs){\ |
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 only these and not the other operators?
If they should not all be changed, the lets leave a comment.
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 believe the ones that do not perform assignment can be constexpr in c++11
This constexpr officially works only with C++14 (assignment to lhs, 2 statements) and actually broke some C++11 compilers
Fixes #8857