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

            Bug ID: 119838
           Summary: optional template keyword causing error
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

I believe this should compile:

```
template<typename T>
struct S { using U = T; static const int x = 0; };
void
g ()
{
  ::S<int>::U a;
  ::template S<int>::U b;
  auto c = ::S<int>::x;
  auto d = ::template S<int>::x;
}
```

because "::template S<int>::" should match the 

nested-name-specifier template(opt) simple-template-id ::

production where the template is optional.  But we emit:

g.C: In function ‘void g()’:
g.C:7:24: error: qualified-id in declaration before ‘b’
    7 |   ::template S<int>::U b;
      |                        ^
g.C:9:14: error: expected id-expression before ‘template’
    9 |   auto d = ::template S<int>::x;
      |              ^~~~~~~~


Other compilers accept the code.

Reply via email to