Skip to content

flatbuffers.h: fix C++11 compilation (#8857)#8858

Merged
jtdavis777 merged 1 commit intogoogle:masterfrom
objectbox:8857-cpp-11-constexpr-fix
Feb 4, 2026
Merged

flatbuffers.h: fix C++11 compilation (#8857)#8858
jtdavis777 merged 1 commit intogoogle:masterfrom
objectbox:8857-cpp-11-constexpr-fix

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

@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
@jtdavis777
Copy link
Collaborator

@greenrobot could you please rebase this on master? I'd like to get this merged :D

@jtdavis777 jtdavis777 added waiting-for-update This PR is waiting for a change from the author or contributors before it is ready for merge and removed ready-for-merge This PR has been approved by a maintainer and is ready for merge by a code owner labels Feb 4, 2026
@greenrobot greenrobot force-pushed the 8857-cpp-11-constexpr-fix branch from 0b84039 to 84e6dbc Compare February 4, 2026 13:00
@greenrobot
Copy link
Contributor Author

@jtdavis777 Rebased

@jtdavis777 jtdavis777 enabled auto-merge (squash) February 4, 2026 13:13
@jtdavis777
Copy link
Collaborator

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
auto-merge was automatically disabled February 4, 2026 13:25

Head branch was pushed to by a user without write access

@greenrobot greenrobot force-pushed the 8857-cpp-11-constexpr-fix branch from 84e6dbc to bacdbb2 Compare February 4, 2026 13:25
@greenrobot
Copy link
Contributor Author

@jtdavis777 rebased again, just in case...

@jtdavis777 jtdavis777 enabled auto-merge (squash) February 4, 2026 13:30
@jtdavis777
Copy link
Collaborator

👍 kicked off the builds! 🤞

@jtdavis777 jtdavis777 merged commit e5a9ff7 into google:master Feb 4, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ waiting-for-update This PR is waiting for a change from the author or contributors before it is ready for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ 11 compilation broken

3 participants