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

            Bug ID: 107124
           Summary: Reference template parameter refers to a temporary
                    object
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following program is accepted by Clang:

template<int>
struct A {};

template<const int & I>
constexpr int f(A<I>) { return 0; }

template<class T>
constexpr int f(T) { return 1; }

static_assert( f(A<0>{}) == 1 );

But in GCC static assertion fails, because f(A<I>) overload is preferred.
Online demo: https://gcc.godbolt.org/z/9hj4WoT7b

But this is illegal by http://eel.is/c++draft/temp.arg.nontype#3.1, since const
int & I cannot refer to a temporary int 0.

Reply via email to