Skip to content

[Clang][Sema] Treat explicit specializations of static data member templates declared without 'static' as static data members when diagnosing uses of 'auto' #97425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

sdkrystian
Copy link
Member

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.

…mplates declared without 'static' as static data members when diagnosing uses of 'auto'
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2024

@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)

Changes

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&lt;int N&gt;
  static constexpr auto x = 0;

  template&lt;&gt;
  constexpr auto x&lt;1&gt; = 1; // error: 'auto' not allowed in non-static struct member
};

This patch fixes the issue.


Full diff: https://github.com/llvm/llvm-project/pull/97425.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaType.cpp (+1-2)
  • (added) clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5-cxx14.cpp (+12)
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}}
+};

@sdkrystian sdkrystian merged commit 584e431 into llvm:main Jul 3, 2024
10 checks passed
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
…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.
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Oct 28, 2024
cherry-picked:
9e1f1cf sdkrystian@gmail.com      Tue Jul  9 16:40:53 2024 -0400 [Clang][Sema] Handle class member access expressions with valid nested-name-specifiers that become invalid after lookup (llvm#98167)
584e431 sdkrystian@gmail.com      Wed Jul  3 12:12:53 2024 -0400 [Clang][Sema] Treat explicit specializations of static data member templates declared without 'static' as static data members when diagnosing uses of 'auto' (llvm#97425)
a1bce0b dblaikie@gmail.com        Thu Jun 27 08:17:40 2024 -0700 Clang: Add warning flag for storage class specifiers on explicit specializations (llvm#96699)
f46d146 erickvelez7@gmail.com     Fri May 31 11:02:21 2024 -0700 [clang] require template arg list after template kw (llvm#80801)
033ec09 hanwei62@huawei.com       Fri Dec 22 09:00:41 2023 +0800 [Clang][Sema] Fix Wswitch-default bad warning in template (llvm#76007)
c281782 dongjianqiang2@huawei.com Thu Dec  7 09:03:15 2023 +0800 [clang][Sema] Add -Wswitch-default warning option (llvm#73077)

Change-Id: Ib2582201b01cc62c3bf62011347925556e8531f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants