https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124214

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #3 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Jonathan Wakely from comment #1)
> That's intentional, in the current C++ standard it's only an error when you
> try to use that function during constant evaluation.

Note that modifying the example accordingly shows that the diagnostic for that
is incomplete up to and including GCC 15, but it seems to work with GCC trunk.
I'm not seeing another bug for this, should I open one or is this something
that's fine to have fixed for GCC 16 only?

template< typename T = int >
class foo {
public:
    static constexpr int bar(T x){
        (void) x;
        return 42;
    }
};

int f(int x){
    constexpr int y = foo<>::bar( 0 );
    return x + y;
}

GCC 15:

<source>: In function 'int f(int)':
<source>:11:33: error: 'static constexpr int foo<T>::bar(T) [with T = int]'
called in a constant expression
   11 |     constexpr int y = foo<>::bar( 0 );
      |                       ~~~~~~~~~~^~~~~
<source>:4:26: note: 'static constexpr int foo<T>::bar(T) [with T = int]' is
not usable as a 'constexpr' function because:
    4 |     static constexpr int bar(T x){
      |                          ^~~

https://godbolt.org/z/bbbWc5zjo

GCC trunk:

<source>: In function 'int f(int)':
<source>:11:33: error: 'static constexpr int foo<T>::bar(T) [with T = int]'
called in a constant expression
   11 |     constexpr int y = foo<>::bar( 0 );
      |                       ~~~~~~~~~~^~~~~
<source>:4:26: note: 'static constexpr int foo<T>::bar(T) [with T = int]' is
not usable as a 'constexpr' function because:
    4 |     static constexpr int bar(T x){
      |                          ^~~
<source>:4:26: error: body of 'constexpr' function 'static constexpr int
foo<T>::bar(T) [with T = int]' not a return-statement

https://godbolt.org/z/q3c1j9oev

Reply via email to