flatbuffers.h: fix C++11 compilation (#8857)#8858
Conversation
|
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 |
|
@greenrobot could you please rebase this on master? I'd like to get this merged :D |
0b84039 to
84e6dbc
Compare
|
@jtdavis777 Rebased |
|
I may need you to do so again... I think I can only merge PRs that are off the tip of master. but let's see if this auto merge goes through. Sorry - I am fighting with the repo permissions a little. |
This constexpr officially works only with C++14 (assignment to lhs, 2 statements) and actually broke some C++11 compilers
Head branch was pushed to by a user without write access
84e6dbc to
bacdbb2
Compare
|
@jtdavis777 rebased again, just in case... |
|
👍 kicked off the builds! 🤞 |
This constexpr officially works only with C++14 (assignment to lhs, 2 statements) and actually broke some C++11 compilers
Fixes #8857