[clang] 584e431 - [Clang][Sema] Treat explicit specializations of static data member templates declared without 'static' as static data members when diagnosing uses of 'auto' (#97425)

via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 09:12:57 PDT 2024


Author: Krystian Stasiowski
Date: 2024-07-03T12:12:53-04:00
New Revision: 584e431a4b257098d1ff13a0e9926842222ba601

URL: https://github.com/llvm/llvm-project/commit/584e431a4b257098d1ff13a0e9926842222ba601
DIFF: https://github.com/llvm/llvm-project/commit/584e431a4b257098d1ff13a0e9926842222ba601.diff

LOG: [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.

Added: 
    clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5-cxx14.cpp

Modified: 
    clang/lib/Sema/SemaType.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 50c15a1aa89e8..066003c47eb43 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -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)) {

diff  --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5-cxx14.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5-cxx14.cpp
new file mode 100644
index 0000000000000..8f3dac2426a30
--- /dev/null
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5-cxx14.cpp
@@ -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}}
+};


        


More information about the cfe-commits mailing list