[Bug c++/96411] New: erroneous "trait used in its own initializer" error when using concepts in a requirement

barry.revzin at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Aug 1 15:34:47 GMT 2020


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

            Bug ID: 96411
           Summary: erroneous "trait used in its own initializer" error
                    when using concepts in a requirement
           Product: gcc
           Version: 10.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: ---

Reduced from StackOverflow (https://stackoverflow.com/q/63202619/2069064):

template <typename> constexpr bool trait = true;
template <typename T> concept C = trait<T>;

void f(auto) {
  []<typename T>(){
    requires { C<T>; };
  };
}

int main() { f(42); }

This fails on gcc 10.2 with:

<source>: In instantiation of 'void f(auto:1) [with auto:1 = int]':
<source>:10:18:   required from here
<source>:2:31:   required by the constraints of 'template<class T> concept C'
<source>:2:35: error: the value of 'trait<T>' is not usable in a constant
expression
    2 | template <typename T> concept C = trait<T>;
      |                                   ^~~~~~~~
<source>:1:36: note: 'trait<T>' used in its own initializer
    1 | template <typename> constexpr bool trait = true;
      |                                    ^~~~~
Compiler returned: 1

But trait<T> isn't used in its own initializer, and trait<T> is certainly
usable in a constant expression.


More information about the Gcc-bugs mailing list