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

            Bug ID: 89048
           Summary: constant evaluation in trailing return type rejected
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

This program is rejected by gcc:

template <int V> struct X { };
template <typename F> constexpr auto f(F f) -> X<f()> { return {}; }

with:

source>:3:53: error: template argument 1 is invalid
    3 | template <typename F> constexpr auto f(F f) -> X<f()> { return {}; }
      |                                                     ^
<source>:3:53: error: template argument 1 is invalid
<source>:3:53: error: template argument 1 is invalid
<source>:3:53: error: template argument 1 is invalid
<source>:3:48: error: invalid template-id
    3 | template <typename F> constexpr auto f(F f) -> X<f()> { return {}; }
      |                                                ^
<source>:3:51: error: use of parameter outside function body before '(' token
    3 | template <typename F> constexpr auto f(F f) -> X<f()> { return {}; }
      |                                                   ^
<source>:3:38: error: deduced class type 'X' in function return type
    3 | template <typename F> constexpr auto f(F f) -> X<f()> { return {}; }
      |                                      ^
<source>:1:25: note: 'template<int V> struct X' declared here
    1 | template <int V> struct X { };
      |                         ^
Compiler returned: 1

On the other hand, this program is accepted:

template <int V> struct X { };
template <typename F> constexpr auto g(F f) { return X<f()>{}; }

Clang accepts both. I think both programs are valid.

Reply via email to