[Clang][Sema] Treat explicit specializations of static data member templates declared without 'static' as static data members when diagnosing uses of 'auto'#97425
Merged
sdkrystian merged 1 commit intollvm:mainfrom Jul 3, 2024
Conversation
…mplates declared without 'static' as static data members when diagnosing uses of 'auto'
Member
|
@llvm/pr-subscribers-clang Author: Krystian Stasiowski (sdkrystian) ChangesAfter #93873 clang no longer permits declarations of explicit specializations of static data member templates to use the 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. Full diff: https://github.com/llvm/llvm-project/pull/97425.diff 2 Files Affected:
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}}
+};
|
zygoloid
approved these changes
Jul 2, 2024
mizvekov
approved these changes
Jul 3, 2024
alexfh
approved these changes
Jul 3, 2024
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After #93873 clang no longer permits declarations of explicit specializations of static data member templates to use the
autoplaceholder-type-specifier:This patch fixes the issue.