-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
[Clang][Sema] Convert warning for extraneous template parameter lists to an extension warning #82277
Merged
Conversation
This file contains 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
llvmbot
added
clang
Clang issues not falling into any other category
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
labels
Feb 19, 2024
@llvm/pr-subscribers-clang Author: Krystian Stasiowski (sdkrystian) ChangesWe currently accept the following explicit specialization with a warning for the extraneous template parameter list: template<typename T>
void f();
template<>
template<>
void f<int>(); // warning: extraneous template parameter list in template specialization This should really be an extension warning so we reject with Full diff: https://github.com/llvm/llvm-project/pull/82277.diff 5 Files Affected:
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..1a7b91bb4b45b6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5323,7 +5323,7 @@ def err_alias_template_extra_headers : Error<
def err_template_spec_extra_headers : Error<
"extraneous template parameter list in template specialization or "
"out-of-line template definition">;
-def warn_template_spec_extra_headers : Warning<
+def ext_template_spec_extra_headers : ExtWarn<
"extraneous template parameter list in template specialization">;
def note_explicit_template_spec_does_not_need_header : Note<
"'template<>' header not required for explicitly-specialized class %0 "
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index cf781e0e1bf3f4..73c0167ab75778 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -3667,7 +3667,7 @@ TemplateParameterList *Sema::MatchTemplateParametersToScopeSpecifier(
if (!SuppressDiagnostic)
Diag(ParamLists[ParamIdx]->getTemplateLoc(),
- AllExplicitSpecHeaders ? diag::warn_template_spec_extra_headers
+ AllExplicitSpecHeaders ? diag::ext_template_spec_extra_headers
: diag::err_template_spec_extra_headers)
<< SourceRange(ParamLists[ParamIdx]->getTemplateLoc(),
ParamLists[ParamLists.size() - 2]->getRAngleLoc());
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p23.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p23.cpp
index 469c4e091953c3..683392c5891538 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p23.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p23.cpp
@@ -1,7 +1,6 @@
// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify %s
-// FIXME: This should be an error with -pedantic-errors.
-template<> // expected-warning {{extraneous template parameter list in template specialization}}
+template<> // expected-error {{extraneous template parameter list in template specialization}}
void f(auto);
template<typename>
@@ -18,7 +17,6 @@ void A<T>::g(auto) { }
template<>
void A<int>::g(auto) { }
-// FIXME: This should be an error with -pedantic-errors.
template<>
-template<> // expected-warning {{extraneous template parameter list in template specialization}}
+template<> // expected-error {{extraneous template parameter list in template specialization}}
void A<long>::g(auto) { }
diff --git a/clang/test/CXX/drs/dr5xx.cpp b/clang/test/CXX/drs/dr5xx.cpp
index 21a6646d4abcf1..0e1de342f6706f 100644
--- a/clang/test/CXX/drs/dr5xx.cpp
+++ b/clang/test/CXX/drs/dr5xx.cpp
@@ -354,17 +354,15 @@ namespace dr531 { // dr531: partial
template<> void A<char>::f(char) {}
// expected-error@-1 {{no function template matches function template specialization 'f'}}
- // FIXME: This is ill-formed; -pedantic-errors should reject.
template<> template<typename U> void A<char>::g(char, U) {}
- // expected-warning@-1 {{extraneous template parameter list in template specialization}}
+ // expected-error@-1 {{extraneous template parameter list in template specialization}}
// expected-note@#dr531-A-char {{'template<>' header not required for explicitly-specialized class 'dr531::bad::A<char>' declared here}}
template<> struct A<char>::B {};
// expected-error@-1 {{extraneous 'template<>' in declaration of struct 'B'}}
// expected-error@-2 {{specialization of member 'dr531::bad::A<char>::B' does not specialize an instantiated member}}
// expected-note@#dr531-B {{attempt to specialize declaration here}}
- // FIXME: This is ill-formed; -pedantic-errors should reject.
template<> template<typename U> struct A<char>::C {};
- // expected-warning@-1 {{extraneous template parameter list in template specialization}}
+ // expected-error@-1 {{extraneous template parameter list in template specialization}}
// expected-note@#dr531-A-char {{'template<>' header not required for explicitly-specialized class 'dr531::bad::A<char>' declared here}}
template<> char A<char>::n = 0;
// expected-error@-1 {{extraneous 'template<>' in declaration of variable 'n'}}
@@ -808,7 +806,7 @@ namespace dr571 { // dr571 unknown
int n;
// FIXME: Test if this has internal linkage.
const ir r = n;
- // expected-warning@-1 {{'const' qualifier on reference type 'ir' (aka 'int &') has no effect}}
+ // expected-warning@-1 {{'const' qualifier on reference type 'ir' (aka 'int &') has no effect}}
}
namespace dr572 { // dr572: yes
@@ -990,7 +988,7 @@ namespace dr580 { // dr580: partial
// FIXME: We incorrectly accept this
// because we think C2::Y::A<...> might
// instantiate to C2::X::A
- template<X::I> struct A {};
+ template<X::I> struct A {};
};
};
diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c
index 07a75046d4e01b..9d4cac9e39b420 100644
--- a/clang/test/Misc/warning-flags.c
+++ b/clang/test/Misc/warning-flags.c
@@ -26,6 +26,7 @@ CHECK-NEXT: ext_missing_whitespace_after_macro_name
CHECK-NEXT: ext_new_paren_array_nonconst
CHECK-NEXT: ext_plain_complex
CHECK-NEXT: ext_template_arg_extra_parens
+CHECK-NEXT: ext_template_spec_extra_headers
CHECK-NEXT: ext_typecheck_cond_incompatible_operands
CHECK-NEXT: ext_typecheck_ordered_comparison_of_pointer_integer
CHECK-NEXT: ext_using_undefined_std
@@ -78,7 +79,6 @@ CHECK-NEXT: warn_register_objc_catch_parm
CHECK-NEXT: warn_related_result_type_compatibility_class
CHECK-NEXT: warn_related_result_type_compatibility_protocol
CHECK-NEXT: warn_template_export_unsupported
-CHECK-NEXT: warn_template_spec_extra_headers
CHECK-NEXT: warn_tentative_incomplete_array
CHECK-NEXT: warn_typecheck_function_qualifiers
CHECK-NEXT: warn_undef_interface
|
sdkrystian
force-pushed
the
extra-tpl
branch
from
February 20, 2024 15:07
7abf178
to
e2d0e6a
Compare
erichkeane
approved these changes
Feb 20, 2024
… to an extension warning
sdkrystian
force-pushed
the
extra-tpl
branch
from
February 20, 2024 17:59
c61e21d
to
0ba458f
Compare
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
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.
We currently accept the following explicit specialization with a warning for the extraneous template parameter list:
This should really be an extension warning so we reject with
-pedantic-errors
. This patch converts the warning to an extension warning.(Note: This still needs a release note & a few new tests... I'll be taking care of that tomorrow)