Home > database >  Prefixing invalid variable definition with `struct` causes C template to compile
Prefixing invalid variable definition with `struct` causes C template to compile

Time:01-04

class Base {
  int i;
};

template <auto V>
struct Foo {
  int a;
};


int main()
{
    struct Foo<&Base::i> struct_foo;
    Foo<&Base::i> foo;
}

The fist line in main() compiles in gcc 12.2, but the second line doesn't compile. What is the reason?

https://godbolt.org/z/eTG7cW35q

CodePudding user response:

This seems to be a gcc bug as both statements should fail compilation(which they do with clang and msvc).

Demo

  • Related