Skip to content

Conversation

@greenrobot
Copy link
Contributor

This constexpr officially works only with C++14 (assignment to lhs, 2 statements) and actually broke some C++11 compilers

Fixes #8857

This constexpr officially works only with C++14 (assignment to lhs, 2 statements) and actually broke some C++11 compilers
@github-actions github-actions bot added the c++ label Dec 16, 2025
@jtdavis777
Copy link
Collaborator

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 )

@greenrobot
Copy link
Contributor Author

would it not be better to rewrite these expressions to be constexpr 11 compatible?

I don't think it can be done, as constexpr cannot contain an assignment (lhs is assigned).

would it not be better to rewrite these expressions to be constexpr 11 compatible?

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.

@jtdavis777
Copy link
Collaborator

Got it! Sounds good. Figured it was worth a quick check.

@dbaileychess
Copy link
Collaborator

C++11 is very old. Do people still target that?

@jtdavis777
Copy link
Collaborator

I believe it is still the officially supported version of flatc, and this change doesn't hurt anything to go in

@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
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ^ (E lhs, E rhs){\
return E(T(lhs) ^ T(rhs));\
}\
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ~ (E lhs){\
Copy link
Collaborator

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.

Copy link
Collaborator

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

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

Labels

c++ 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.

C++ 11 compilation broken

3 participants