You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error "body of ‘constexpr’ function is not return statement" on build #410
Building with gcc 11.4. 0 on current develop the following error arises:
[...]
ALP/include/graphblas/base/distribution.hpp:140:33: error: body of ‘constexpr’ function‘static constexpr size_t grb::internal::Distribution<backend>::local_offset(size_t, size_t, size_t) [with grb::Backend backend = grb::reference; size_t = long unsigned int]’ not a return-statement
Indeed the C++-11 standard dictates that the body of a constexpr function must contain only a return statement (see here ).
The function that triggers the error is the following:
Removing the (void) ... statements, but this results in warnings about unused parameters, which is the reason I introduced those lines in the first place.
Of course we could suppress such warnings, but that's definitely something I would avoid if possible.
Somehow telling the compiler to use a newer C++ standard when compiling this file, as newer versions allow such constexpr functions
Furthermore the fact that testing passed on the CI and previous testing means that we are likely not explicitly telling the compiler to use a fixed C++ standard version.
I think we should consider this to avoid this kind of unexpected compile errors.
Ah I see what you mean! What is strange is that GCC13 accepts it. Could you check whether bumping the C++ standard to 17 "solves" the issue for GCC11?
From:Giovanni Gaio ***@***.******@***.***>>
To:Algebraic-Programming/ALP ***@***.******@***.***>>
Cc:Subscribed ***@***.******@***.***>>
Date:2026-02-17 11:12:00
Subject:Re: [Algebraic-Programming/ALP] Error "body of ‘constexpr’ function is not return statement" on build (Issue #410)
[https://avatars.githubusercontent.com/u/48856010?s=20&v=4]GiovaGa left a comment(Algebraic-Programming/ALP#410)<#410 (comment)>
This issue is definitely related to #373<#373> , and in my opinion supports the bump to C++17
—
I read some specs -- it seems to me that the related lines are null statements, and the spec in C++11 actually allows for null statements in the body of a constexpr function. Hence I believe GCC13's behaviour is correct. It may be good to check if GCC 11.5 still has this issue, and otherwise report it there?
Thanks Giovanni. Given error still persists with GCC 11.5, we can / should also raise a bug report on GCC. We can also check my reading of the spec that way. That doesn't solve the issue for anyone who wants to compile ALP with GCC 11 though, so the check with -std=c++17 is still very useful
In a minimal example the error is raised with both versions of gcc (specifying -std=c++11, that maybe is implicit in the building infrastructure of ALP).
Interestingly clang 18.1.3 shows this as a warning (and not an error)
I will check the specification once again to understand if this is indeed the intended behavior.
So we have that the code we think is correct in ANSI C++11 does not compile with -std=c++11 on GCC 14.2.0 (not latest -> 14.3), GCC 13.3.0 (not latest -> 13.4), and GCC 11.5 (latest). It means we can / should raise it as a bug in GCC 11?
On the other hand, it works as it should on LLVM /Clang 18.1.13 and GCC 14.3.1.
For fixing it on our side we have that bumping to ANSI C++17 avoids this issue as well. @djelovina@p-anastas do you have strong opinions on this? I myself am a bit hesitant doing this just before releasing v0.8, it seems more wise to make such a bump after the release
So we have that the code we think is correct in ANSI C++11 does not compile with -std=c++11 on GCC 14.2.0 (not latest -> 14.3), GCC 13.3.0 (not latest -> 13.4), and GCC 11.5 (latest). It means we can / should raise it as a bug in GCC 11?
I think I wasn't clear on what I did test: the reported versions (14.2.0, 13.3.0, 11.5.0) do not compile the minimal example above, but of these only 11.5.0 fails to build ALP
So, the guys from GCC said that (void) x; is not a null statement (we didn't correctly understand the definitions I guess), so GCC 11.5 is right to raise the error, and this is a bug with later versions. (that I was able to reproduce with a minimal program, see it here).
So to be C++11 compliant we must remove the constexpr specifier, or keep the warnings.
For fixing it on our side we have that bumping to ANSI C++17 avoids this issue as well. @djelovina@p-anastas do you have strong opinions on this? I myself am a bit hesitant doing this just before releasing v0.8, it seems more wise to make such a bump after the release
There is not urgency from my side to do if before v0.8
Activity
GiovaGa commentedon Feb 17, 2026
This issue is definitely related to #373 , and in my opinion supports the bump to C++17
anyzelman commentedon Feb 17, 2026
anyzelman commentedon Feb 19, 2026
I read some specs -- it seems to me that the related lines are null statements, and the spec in C++11 actually allows for null statements in the body of a constexpr function. Hence I believe GCC13's behaviour is correct. It may be good to check if GCC 11.5 still has this issue, and otherwise report it there?
GiovaGa commentedon Feb 19, 2026
I am now able to test using gcc 11.5.0, and this seems to still be an issue
I will now try also bumping to c++17 and seeing what happens
anyzelman commentedon Feb 19, 2026
Thanks Giovanni. Given error still persists with GCC 11.5, we can / should also raise a bug report on GCC. We can also check my reading of the spec that way. That doesn't solve the issue for anyone who wants to compile ALP with GCC 11 though, so the check with
-std=c++17is still very usefulanyzelman commentedon Feb 19, 2026
(Also other workarounds are of course possible)
GiovaGa commentedon Feb 19, 2026
Adding
-std=c++17successfully compiles with both gcc 11.5.0 and gcc 13.3.0Some warnings appear with gcc-13
GiovaGa commentedon Feb 19, 2026
In a minimal example the error is raised with both versions of gcc (specifying
-std=c++11, that maybe is implicit in the building infrastructure of ALP).Interestingly clang 18.1.3 shows this as a warning (and not an error)
I will check the specification once again to understand if this is indeed the intended behavior.
anyzelman commentedon Feb 19, 2026
GCC 14.3.1 is the one that accepts it, apologies (it's the CentOS Stream 10's default)
GiovaGa commentedon Feb 19, 2026
The specification seems pretty clear that null statements are allowed inside
constexprfunctions in c++11My minimal example:
Also throws an error when compiling as
g++-14 x.cpp -std=c++11 -Wall -Wextra -c, but this is gcc 14.2.0anyzelman commentedon Feb 20, 2026
So we have that the code we think is correct in ANSI C++11 does not compile with -std=c++11 on GCC 14.2.0 (not latest -> 14.3), GCC 13.3.0 (not latest -> 13.4), and GCC 11.5 (latest). It means we can / should raise it as a bug in GCC 11?
On the other hand, it works as it should on LLVM /Clang 18.1.13 and GCC 14.3.1.
anyzelman commentedon Feb 20, 2026
For fixing it on our side we have that bumping to ANSI C++17 avoids this issue as well. @djelovina @p-anastas do you have strong opinions on this? I myself am a bit hesitant doing this just before releasing v0.8, it seems more wise to make such a bump after the release
GiovaGa commentedon Feb 20, 2026
I reported it to GCC (see here), we'll see what happens there
GiovaGa commentedon Feb 20, 2026
I think I wasn't clear on what I did test: the reported versions (14.2.0, 13.3.0, 11.5.0) do not compile the minimal example above, but of these only 11.5.0 fails to build ALP
GiovaGa commentedon Feb 23, 2026
So, the guys from GCC said that
(void) x;is not a null statement (we didn't correctly understand the definitions I guess), so GCC 11.5 is right to raise the error, and this is a bug with later versions. (that I was able to reproduce with a minimal program, see it here).So to be C++11 compliant we must remove the
constexprspecifier, or keep the warnings.djelovina commentedon Feb 23, 2026
There is not urgency from my side to do if before v0.8