[Bug c++/89048] constant evaluation in trailing return type rejected

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jan 6 23:23:13 GMT 2022


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
ICC gives:
<source>(3): error: a parameter is not allowed
  template <typename F> constexpr auto f(F f) -> X<f()> { return {}; }
                                                   ^

Which I think is a better error message than what GCC gives.

For the other case it is rejected at instaintation time.
That is take:
template <int V> struct X { };
template <typename F> constexpr auto g(F f) { return X<f()>{}; }
constexpr int h(void) {return 0;}
int t = g(&h);

GCC error message is:
<source>: In instantiation of 'constexpr auto g(F) [with F = int (*)()]':
<source>:5:10:   required from here
<source>:3:61: error: 'f' is not a constant expression
    3 | template <typename F> constexpr auto g(F f) { return X<f()>{}; }
      |                                                             ^
<source>:3:57: note: in template argument for type 'int'
    3 | template <typename F> constexpr auto g(F f) { return X<f()>{}; }
      |                                                        ~^~


More information about the Gcc-bugs mailing list