Skip to content

Commit 2bb667e

Browse files
committed
[Clang][Parse] Diagnose member template declarations with multiple declarators
1 parent 05e85e4 commit 2bb667e

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ Improvements to Clang's diagnostics
596596
13 | new (__builtin_memset) S {};
597597
| ^
598598
599+
- Clang now diagnoses member template declarations with multiple declarators.
600+
599601

600602
Improvements to Clang's time-trace
601603
----------------------------------

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3167,6 +3167,15 @@ Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS,
31673167

31683168
DeclaratorInfo.complete(ThisDecl);
31693169

3170+
if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
3171+
if (Tok.is(tok::comma)) {
3172+
Diag(Tok, diag::err_multiple_template_declarators)
3173+
<< (int)TemplateInfo.Kind;
3174+
SkipUntil(tok::semi, StopBeforeMatch);
3175+
}
3176+
break;
3177+
}
3178+
31703179
// If we don't have a comma, it is either the end of the list (a ';')
31713180
// or an error, bail out.
31723181
SourceLocation CommaLoc;

clang/test/CXX/temp/p3.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ template<typename T> struct B { } f(); // expected-error {{expected ';' after st
1515
template<typename T> struct C { } // expected-error {{expected ';' after struct}}
1616

1717
A<int> c;
18+
19+
struct D {
20+
template<typename T> static const int x = 0, f(); // expected-error {{can only declare a single entity}}
21+
22+
template<typename T> static const int g(), y = 0; // expected-error {{can only declare a single entity}}
23+
};

clang/test/OpenMP/declare_simd_messages.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ int main();
3333
int main();
3434

3535
struct A {
36-
// expected-error@+1 {{function declaration is expected after 'declare simd' directive}}
3736
#pragma omp declare simd
3837
template<typename T>
39-
T infunc1(T a), infunc2(T a);
38+
T infunc1(T a);
4039
};
4140

4241
// expected-error@+1 {{single declaration is expected after 'declare simd' directive}}

0 commit comments

Comments
 (0)