Skip to content

Commit

Permalink
[Clang][Sema] Treat explicit specializations of static data member te…
Browse files Browse the repository at this point in the history
…mplates declared without 'static' as static data members when diagnosing uses of 'auto' (llvm#97425)

After llvm#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.
  • Loading branch information
sdkrystian authored Jul 3, 2024
1 parent 3ab2247 commit 584e431
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3194,8 +3194,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
break;
}
case DeclaratorContext::Member: {
if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
D.isFunctionDeclarator())
if (D.isStaticMember() || D.isFunctionDeclarator())
break;
bool Cxx = SemaRef.getLangOpts().CPlusPlus;
if (isa<ObjCContainerDecl>(SemaRef.CurContext)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14

struct A {
template<int N>
static constexpr auto x = N;

template<>
constexpr auto x<1> = 1;

template<>
static constexpr auto x<2> = 2; // expected-warning{{explicit specialization cannot have a storage class}}
};

0 comments on commit 584e431

Please sign in to comment.