Skip to content

Commit 396f51a

Browse files
committed
[Clang][Parse] Diagnose member template declarations with multiple declarators
1 parent c5edef6 commit 396f51a

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
@@ -114,6 +114,8 @@ Improvements to Clang's diagnostics
114114
- Clang now applies syntax highlighting to the code snippets it
115115
prints.
116116

117+
- Clang now diagnoses member template declarations with multiple declarators.
118+
117119
Improvements to Clang's time-trace
118120
----------------------------------
119121

clang/lib/Parse/ParseDeclCXX.cpp

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

32633263
DeclaratorInfo.complete(ThisDecl);
32643264

3265+
if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) {
3266+
if (Tok.is(tok::comma)) {
3267+
Diag(Tok, diag::err_multiple_template_declarators)
3268+
<< (int)TemplateInfo.Kind;
3269+
SkipUntil(tok::semi, StopBeforeMatch);
3270+
}
3271+
break;
3272+
}
3273+
32653274
// If we don't have a comma, it is either the end of the list (a ';')
32663275
// or an error, bail out.
32673276
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)