Skip to content

Commit 584e431

Browse files
authored
[Clang][Sema] Treat explicit specializations of static data member templates declared without 'static' as static data members when diagnosing uses of 'auto' (#97425)
After #93873 clang no longer permits declarations of explicit specializations of static data member templates to use the `auto` _placeholder-type-specifier_: ``` struct A { template<int N> static constexpr auto x = 0; template<> constexpr auto x<1> = 1; // error: 'auto' not allowed in non-static struct member }; ``` This patch fixes the issue.
1 parent 3ab2247 commit 584e431

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,8 +3194,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
31943194
break;
31953195
}
31963196
case DeclaratorContext::Member: {
3197-
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
3198-
D.isFunctionDeclarator())
3197+
if (D.isStaticMember() || D.isFunctionDeclarator())
31993198
break;
32003199
bool Cxx = SemaRef.getLangOpts().CPlusPlus;
32013200
if (isa<ObjCContainerDecl>(SemaRef.CurContext)) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
2+
3+
struct A {
4+
template<int N>
5+
static constexpr auto x = N;
6+
7+
template<>
8+
constexpr auto x<1> = 1;
9+
10+
template<>
11+
static constexpr auto x<2> = 2; // expected-warning{{explicit specialization cannot have a storage class}}
12+
};

0 commit comments

Comments
 (0)