Skip to content

Error "body of ‘constexpr’ function is not return statement" on build #410

Open

Description

@GiovaGa

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:

https://github.com/Algebraic-Programming/ALP/blob/2bd1a9ee8b53853199255b26283179d30578f2f3/include/graphblas/base/distribution.hpp#L132C1-L140C6

I see two possible solutions:

  1. 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.
  2. 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.

Activity

  1. GiovaGa commented on Feb 17, 2026

    @GiovaGa
    CollaboratorAuthor

    This issue is definitely related to #373 , and in my opinion supports the bump to C++17

  2. anyzelman commented on Feb 17, 2026

    @anyzelman
    Member
  3. anyzelman commented on Feb 19, 2026

    @anyzelman
    Member

    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?

  4. GiovaGa commented on Feb 19, 2026

    @GiovaGa
    CollaboratorAuthor

    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

  5. anyzelman commented on Feb 19, 2026

    @anyzelman
    Member

    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

  6. anyzelman commented on Feb 19, 2026

    @anyzelman
    Member

    (Also other workarounds are of course possible)

  7. GiovaGa commented on Feb 19, 2026

    @GiovaGa
    CollaboratorAuthor

    Adding -std=c++17 successfully compiles with both gcc 11.5.0 and gcc 13.3.0
    Some warnings appear with gcc-13

  8. GiovaGa commented on Feb 19, 2026

    @GiovaGa
    CollaboratorAuthor

    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.

  9. anyzelman commented on Feb 19, 2026

    @anyzelman
    Member

    GCC 14.3.1 is the one that accepts it, apologies (it's the CentOS Stream 10's default)

  10. GiovaGa commented on Feb 19, 2026

    @GiovaGa
    CollaboratorAuthor

    The specification seems pretty clear that null statements are allowed inside constexpr functions in c++11

    My minimal example:

    constexpr int foo(int x, int y){
    	(void) x;
    	(void) y;
    	return 42;
    }
    
    int bar(int x, int y){
    	return foo(x,y);
    }

    Also throws an error when compiling as g++-14 x.cpp -std=c++11 -Wall -Wextra -c, but this is gcc 14.2.0

  11. anyzelman commented on Feb 20, 2026

    @anyzelman
    Member

    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.

  12. anyzelman commented on Feb 20, 2026

    @anyzelman
    Member

    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

  13. GiovaGa commented on Feb 20, 2026

    @GiovaGa
    CollaboratorAuthor

    It means we can / should raise it as a bug in GCC 11?

    I reported it to GCC (see here), we'll see what happens there

  14. GiovaGa commented on Feb 20, 2026

    @GiovaGa
    CollaboratorAuthor

    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

  15. GiovaGa commented on Feb 23, 2026

    @GiovaGa
    CollaboratorAuthor

    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.

  16. djelovina commented on Feb 23, 2026

    @djelovina
    Collaborator

    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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions