According to [temp.pre] p5:
> In a template-declaration, explicit specialization, or explicit instantiation the init-declarator-list in the declaration shall contain at most one declarator.
A member-declaration that is a template-declaration or explicit-specialization contains a declaration, even though it declares a member. This means it _will_ contain an init-declarator-list (not a member-declarator-list), so [temp.pre] p5 applies.
This diagnoses declarations such as:
```
struct A
{
template<typename T>
static const int x = 0, f(); // error: a template declaration can only declare a single entity
template<typename T>
static const int g(), y = 0; // error: a template declaration can only declare a single entity
};
```
The diagnostic messages are the same as those of the equivalent namespace scope declarations.
Note: since we currently do not diagnose declarations with multiple abbreviated function template declarators at namespace scope e.g., `void f(auto), g(auto);`, so this patch does not add diagnostics for the equivalent member declarations.
This patch also refactors `ParseSingleDeclarationAfterTemplate` (now named `ParseDeclarationAfterTemplate`) to call `ParseDeclGroup` and return the resultant `DeclGroup`.
24 lines
904 B
C++
24 lines
904 B
C++
// RUN: %clang_cc1 -verify %s
|
|
|
|
template<typename T> struct S {
|
|
static int a, b;
|
|
};
|
|
|
|
template<typename T> int S<T>::a, S<T>::b; // expected-error {{can only declare a single entity}}
|
|
|
|
template<typename T> struct A { static A a; } A<T>::a; // expected-error {{expected ';' after struct}} \
|
|
expected-error {{use of undeclared identifier 'T'}}
|
|
|
|
template<typename T> struct B { } f(); // expected-error {{expected ';' after struct}} \
|
|
expected-error {{a type specifier is required}}
|
|
|
|
template<typename T> struct C { } // expected-error {{expected ';' after struct}}
|
|
|
|
A<int> c;
|
|
|
|
struct D {
|
|
template<typename T> static const int x = 0, f(); // expected-error {{can only declare a single entity}}
|
|
|
|
template<typename T> static const int g(), y = 0; // expected-error {{can only declare a single entity}}
|
|
};
|