Skip to content

Commit ac894bf

Browse files
committed
Refactor compatibility warnings in Sema
1 parent ce40f50 commit ac894bf

File tree

18 files changed

+154
-243
lines changed

18 files changed

+154
-243
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 57 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,61 @@
1212

1313
let Component = "Sema" in {
1414
let CategoryName = "Semantic Issue" in {
15+
// C++11 compatibility with C++98.
16+
defm nonclass_type_friend : CXX11CompatWarn<"non-class friend type %0 is">;
17+
defm static_data_member_in_union : CXX11CompatWarn<"static data member %0 in union is">;
18+
defm templ_default_in_function_templ : CXX11CompatWarn<
19+
"default template arguments for a function template are">;
20+
defm template_arg_extra_parens : CXX11CompatWarn<
21+
"parentheses around address non-type template argument are">;
22+
defm typename_outside_of_template : CXX11CompatWarn<"'typename' outside of a template is">;
23+
24+
// C++14 compatibility with C++11 and earlier.
25+
defm constexpr_type_definition : CXX14CompatWarn<
26+
"type definition in a constexpr %select{function|constructor}0 is">;
27+
defm constexpr_local_var : CXX14CompatWarn<
28+
"variable declaration in a constexpr %select{function|constructor}0 is">;
29+
defm constexpr_body_multiple_return : CXX14CompatWarn<
30+
"multiple return statements in constexpr function is">;
31+
defm variable_template : CXX14CompatWarn<"variable templates are">;
32+
33+
// C++17 compatibility with C++14 and earlier.
34+
defm decomp_decl : CXX17CompatWarn<"decomposition declarations are">;
35+
defm inline_variable : CXX17CompatWarn<"inline variables are">;
36+
37+
// C++20 compatibility with C++17 and earlier.
38+
defm decomp_decl_spec : CXX20CompatWarn<
39+
"decomposition declaration declared "
40+
"%plural{1:'%1'|:with '%1' specifiers}0 is">;
41+
defm constexpr_local_var_no_init : CXX20CompatWarn<
42+
"uninitialized variable in a constexpr %select{function|constructor}0 is">;
43+
defm constexpr_function_try_block : CXX20CompatWarn<
44+
"function try block in constexpr %select{function|constructor}0 is">;
45+
defm constexpr_union_ctor_no_init : CXX20CompatWarn<
46+
"constexpr union constructor that does not initialize any member is">;
47+
defm constexpr_ctor_missing_init : CXX20CompatWarn<
48+
"constexpr constructor that does not initialize all members is">;
49+
defm adl_only_template_id : CXX20CompatWarn<
50+
"use of function template name with no prior declaration in function call "
51+
"with explicit template arguments is">;
52+
53+
// C++23 compatibility with C++20 and earlier.
54+
defm constexpr_static_var : CXX23CompatWarn<
55+
"definition of a %select{static|thread_local}1 variable "
56+
"in a constexpr %select{function|constructor}0 "
57+
"is">;
58+
59+
// C++26 compatibility with C++23 and earlier.
60+
defm decomp_decl_cond : CXX26CompatWarn<"structured binding declaration in a condition is">;
61+
62+
// Compatibility warnings duplicated across multiple language versions.
63+
foreach std = [14, 20, 23] in {
64+
defm constexpr_body_invalid_stmt : CXXCompatWarn<
65+
"use of this statement in a constexpr %select{function|constructor}0 is",
66+
/*default_ignore=*/false,
67+
std>;
68+
}
69+
1570
def note_previous_decl : Note<"%0 declared here">;
1671
def note_entity_declared_at : Note<"%0 declared here">;
1772
def note_callee_decl : Note<"%0 declared here">;
@@ -523,30 +578,9 @@ def warn_modifying_shadowing_decl :
523578
// C++ decomposition declarations
524579
def err_decomp_decl_context : Error<
525580
"decomposition declaration not permitted in this context">;
526-
def warn_cxx14_compat_decomp_decl : Warning<
527-
"decomposition declarations are incompatible with "
528-
"C++ standards before C++17">, DefaultIgnore, InGroup<CXXPre17Compat>;
529-
def ext_decomp_decl : ExtWarn<
530-
"decomposition declarations are a C++17 extension">, InGroup<CXX17>;
531-
def ext_decomp_decl_cond : ExtWarn<
532-
"structured binding declaration in a condition is a C++2c extenstion">,
533-
InGroup<CXX26>;
534-
def warn_cxx26_decomp_decl_cond : Warning<
535-
"structured binding declaration in a condition is incompatible with "
536-
"C++ standards before C++2c">,
537-
InGroup<CXXPre26Compat>, DefaultIgnore;
538581
def err_decomp_decl_spec : Error<
539582
"decomposition declaration cannot be declared "
540583
"%plural{1:'%1'|:with '%1' specifiers}0">;
541-
def ext_decomp_decl_spec : ExtWarn<
542-
"decomposition declaration declared "
543-
"%plural{1:'%1'|:with '%1' specifiers}0 is a C++20 extension">,
544-
InGroup<CXX20>;
545-
def warn_cxx17_compat_decomp_decl_spec : Warning<
546-
"decomposition declaration declared "
547-
"%plural{1:'%1'|:with '%1' specifiers}0 "
548-
"is incompatible with C++ standards before C++20">,
549-
InGroup<CXXPre20Compat>, DefaultIgnore;
550584
def err_decomp_decl_type : Error<
551585
"decomposition declaration cannot be declared with type %0; "
552586
"declared type must be 'auto' or reference to 'auto'">;
@@ -1695,12 +1729,6 @@ def warn_consteval_if_always_true : Warning<
16951729
"consteval if is always true in an %select{unevaluated|immediate}0 context">,
16961730
InGroup<DiagGroup<"redundant-consteval-if">>;
16971731

1698-
def ext_inline_variable : ExtWarn<
1699-
"inline variables are a C++17 extension">, InGroup<CXX17>;
1700-
def warn_cxx14_compat_inline_variable : Warning<
1701-
"inline variables are incompatible with C++ standards before C++17">,
1702-
DefaultIgnore, InGroup<CXXPre17Compat>;
1703-
17041732
def warn_inline_namespace_reopened_noninline : Warning<
17051733
"inline namespace reopened as a non-inline namespace">,
17061734
InGroup<InlineNamespaceReopenedNoninline>;
@@ -1716,11 +1744,6 @@ def ext_enum_friend : ExtWarn<
17161744
InGroup<DiagGroup<"friend-enum">>;
17171745
def note_enum_friend : Note<
17181746
"remove 'enum%select{| struct| class}0' to befriend an enum">;
1719-
def ext_nonclass_type_friend : ExtWarn<
1720-
"non-class friend type %0 is a C++11 extension">, InGroup<CXX11>;
1721-
def warn_cxx98_compat_nonclass_type_friend : Warning<
1722-
"non-class friend type %0 is incompatible with C++98">,
1723-
InGroup<CXX98Compat>, DefaultIgnore;
17241747
def err_friend_is_member : Error<
17251748
"friends cannot be members of the declaring class">;
17261749
def warn_cxx98_compat_friend_is_member : Warning<
@@ -2152,11 +2175,6 @@ def select_tag_type_kind : TextSubstitution<
21522175
def err_static_data_member_not_allowed_in_anon_struct : Error<
21532176
"static data member %0 not allowed in anonymous "
21542177
"%sub{select_tag_type_kind}1">;
2155-
def ext_static_data_member_in_union : ExtWarn<
2156-
"static data member %0 in union is a C++11 extension">, InGroup<CXX11>;
2157-
def warn_cxx98_compat_static_data_member_in_union : Warning<
2158-
"static data member %0 in union is incompatible with C++98">,
2159-
InGroup<CXX98Compat>, DefaultIgnore;
21602178
def ext_union_member_of_reference_type : ExtWarn<
21612179
"union member %0 has reference type %1, which is a Microsoft extension">,
21622180
InGroup<MicrosoftUnionMemberReference>;
@@ -2904,63 +2922,17 @@ def err_constexpr_non_literal_param : Error<
29042922
"not a literal type">;
29052923
def err_constexpr_body_invalid_stmt : Error<
29062924
"statement not allowed in %select{constexpr|consteval}1 %select{function|constructor}0">;
2907-
def ext_constexpr_body_invalid_stmt : ExtWarn<
2908-
"use of this statement in a constexpr %select{function|constructor}0 "
2909-
"is a C++14 extension">, InGroup<CXX14>;
2910-
def warn_cxx11_compat_constexpr_body_invalid_stmt : Warning<
2911-
"use of this statement in a constexpr %select{function|constructor}0 "
2912-
"is incompatible with C++ standards before C++14">,
2913-
InGroup<CXXPre14Compat>, DefaultIgnore;
2914-
def ext_constexpr_body_invalid_stmt_cxx20 : ExtWarn<
2915-
"use of this statement in a constexpr %select{function|constructor}0 "
2916-
"is a C++20 extension">, InGroup<CXX20>;
2917-
def warn_cxx17_compat_constexpr_body_invalid_stmt : Warning<
2918-
"use of this statement in a constexpr %select{function|constructor}0 "
2919-
"is incompatible with C++ standards before C++20">,
2920-
InGroup<CXXPre20Compat>, DefaultIgnore;
2921-
def ext_constexpr_body_invalid_stmt_cxx23 : ExtWarn<
2922-
"use of this statement in a constexpr %select{function|constructor}0 "
2923-
"is a C++23 extension">, InGroup<CXX23>;
2924-
def warn_cxx20_compat_constexpr_body_invalid_stmt : Warning<
2925-
"use of this statement in a constexpr %select{function|constructor}0 "
2926-
"is incompatible with C++ standards before C++23">,
2927-
InGroup<CXXPre23Compat>, DefaultIgnore;
2928-
def ext_constexpr_type_definition : ExtWarn<
2929-
"type definition in a constexpr %select{function|constructor}0 "
2930-
"is a C++14 extension">, InGroup<CXX14>;
2931-
def warn_cxx11_compat_constexpr_type_definition : Warning<
2932-
"type definition in a constexpr %select{function|constructor}0 "
2933-
"is incompatible with C++ standards before C++14">,
2934-
InGroup<CXXPre14Compat>, DefaultIgnore;
29352925
def err_constexpr_vla : Error<
29362926
"variably-modified type %0 cannot be used in a constexpr "
29372927
"%select{function|constructor}1">;
2938-
def ext_constexpr_local_var : ExtWarn<
2939-
"variable declaration in a constexpr %select{function|constructor}0 "
2940-
"is a C++14 extension">, InGroup<CXX14>;
2941-
def warn_cxx11_compat_constexpr_local_var : Warning<
2942-
"variable declaration in a constexpr %select{function|constructor}0 "
2943-
"is incompatible with C++ standards before C++14">,
2944-
InGroup<CXXPre14Compat>, DefaultIgnore;
2945-
def ext_constexpr_static_var : ExtWarn<
2946-
"definition of a %select{static|thread_local}1 variable "
2947-
"in a constexpr %select{function|constructor}0 "
2948-
"is a C++23 extension">, InGroup<CXX23>;
29492928
def warn_cxx20_compat_constexpr_var : Warning<
2950-
"definition of a %select{static variable|thread_local variable|variable "
2951-
"of non-literal type}1 in a constexpr %select{function|constructor}0 "
2929+
"definition of a variable of non-literal type in a constexpr "
2930+
"%select{function|constructor}0 "
29522931
"is incompatible with C++ standards before C++23">,
29532932
InGroup<CXXPre23Compat>, DefaultIgnore;
29542933
def err_constexpr_local_var_non_literal_type : Error<
29552934
"variable of non-literal type %1 cannot be defined in a constexpr "
29562935
"%select{function|constructor}0 before C++23">;
2957-
def ext_constexpr_local_var_no_init : ExtWarn<
2958-
"uninitialized variable in a constexpr %select{function|constructor}0 "
2959-
"is a C++20 extension">, InGroup<CXX20>;
2960-
def warn_cxx17_compat_constexpr_local_var_no_init : Warning<
2961-
"uninitialized variable in a constexpr %select{function|constructor}0 "
2962-
"is incompatible with C++ standards before C++20">,
2963-
InGroup<CXXPre20Compat>, DefaultIgnore;
29642936
def ext_constexpr_function_never_constant_expr : ExtWarn<
29652937
"%select{constexpr|consteval}1 %select{function|constructor}0 never produces a "
29662938
"constant expression">, InGroup<DiagGroup<"invalid-constexpr">>, DefaultError;
@@ -2982,41 +2954,11 @@ def err_constexpr_return_missing_expr : Error<
29822954
def warn_cxx11_compat_constexpr_body_no_return : Warning<
29832955
"constexpr function with no return statements is incompatible with C++ "
29842956
"standards before C++14">, InGroup<CXXPre14Compat>, DefaultIgnore;
2985-
def ext_constexpr_body_multiple_return : ExtWarn<
2986-
"multiple return statements in constexpr function is a C++14 extension">,
2987-
InGroup<CXX14>;
2988-
def warn_cxx11_compat_constexpr_body_multiple_return : Warning<
2989-
"multiple return statements in constexpr function "
2990-
"is incompatible with C++ standards before C++14">,
2991-
InGroup<CXXPre14Compat>, DefaultIgnore;
29922957
def note_constexpr_body_previous_return : Note<
29932958
"previous return statement is here">;
29942959
def err_ms_constexpr_cannot_be_applied : Error<
29952960
"attribute 'msvc::constexpr' cannot be applied to the %select{constexpr|consteval|virtual}0 function %1">;
29962961

2997-
// C++20 function try blocks in constexpr
2998-
def ext_constexpr_function_try_block_cxx20 : ExtWarn<
2999-
"function try block in constexpr %select{function|constructor}0 is "
3000-
"a C++20 extension">, InGroup<CXX20>;
3001-
def warn_cxx17_compat_constexpr_function_try_block : Warning<
3002-
"function try block in constexpr %select{function|constructor}0 is "
3003-
"incompatible with C++ standards before C++20">,
3004-
InGroup<CXXPre20Compat>, DefaultIgnore;
3005-
3006-
def ext_constexpr_union_ctor_no_init : ExtWarn<
3007-
"constexpr union constructor that does not initialize any member "
3008-
"is a C++20 extension">, InGroup<CXX20>;
3009-
def warn_cxx17_compat_constexpr_union_ctor_no_init : Warning<
3010-
"constexpr union constructor that does not initialize any member "
3011-
"is incompatible with C++ standards before C++20">,
3012-
InGroup<CXXPre20Compat>, DefaultIgnore;
3013-
def ext_constexpr_ctor_missing_init : ExtWarn<
3014-
"constexpr constructor that does not initialize all members "
3015-
"is a C++20 extension">, InGroup<CXX20>;
3016-
def warn_cxx17_compat_constexpr_ctor_missing_init : Warning<
3017-
"constexpr constructor that does not initialize all members "
3018-
"is incompatible with C++ standards before C++20">,
3019-
InGroup<CXXPre20Compat>, DefaultIgnore;
30202962
def note_constexpr_ctor_missing_init : Note<
30212963
"member not initialized by constructor">;
30222964
def note_non_literal_no_constexpr_ctors : Note<
@@ -5293,12 +5235,6 @@ def note_template_param_prev_default_arg_in_other_module : Note<
52935235
"previous default template argument defined in module %0">;
52945236
def err_template_param_default_arg_missing : Error<
52955237
"template parameter missing a default argument">;
5296-
def ext_template_parameter_default_in_function_template : ExtWarn<
5297-
"default template arguments for a function template are a C++11 extension">,
5298-
InGroup<CXX11>;
5299-
def warn_cxx98_compat_template_parameter_default_in_function_template : Warning<
5300-
"default template arguments for a function template are incompatible with C++98">,
5301-
InGroup<CXX98Compat>, DefaultIgnore;
53025238
def err_template_parameter_default_template_member : Error<
53035239
"cannot add a default template argument to the definition of a member of a "
53045240
"class template">;
@@ -5307,11 +5243,6 @@ def err_template_parameter_default_friend_template : Error<
53075243
def err_template_template_parm_no_parms : Error<
53085244
"template template parameter must have its own template parameters">;
53095245

5310-
def ext_variable_template : ExtWarn<"variable templates are a C++14 extension">,
5311-
InGroup<CXX14>;
5312-
def warn_cxx11_compat_variable_template : Warning<
5313-
"variable templates are incompatible with C++ standards before C++14">,
5314-
InGroup<CXXPre14Compat>, DefaultIgnore;
53155246
def err_template_variable_noparams : Error<
53165247
"extraneous 'template<>' in declaration of variable %0">;
53175248
def err_template_member : Error<"non-static data member %0 cannot be declared as a template">;
@@ -5321,15 +5252,6 @@ def err_template_member_noparams : Error<
53215252
def err_template_tag_noparams : Error<
53225253
"extraneous 'template<>' in declaration of %0 %1">;
53235254

5324-
def warn_cxx17_compat_adl_only_template_id : Warning<
5325-
"use of function template name with no prior function template "
5326-
"declaration in function call with explicit template arguments "
5327-
"is incompatible with C++ standards before C++20">,
5328-
InGroup<CXXPre20Compat>, DefaultIgnore;
5329-
def ext_adl_only_template_id : ExtWarn<
5330-
"use of function template name with no prior declaration in function call "
5331-
"with explicit template arguments is a C++20 extension">, InGroup<CXX20>;
5332-
53335255
def warn_unqualified_call_to_std_cast_function : Warning<
53345256
"unqualified call to '%0'">, InGroup<DiagGroup<"unqualified-std-cast-call">>;
53355257

@@ -5468,11 +5390,6 @@ def err_template_arg_not_pointer_to_member_form : Error<
54685390
"non-type template argument is not a pointer to member constant">;
54695391
def err_template_arg_invalid : Error<
54705392
"non-type template argument '%0' is invalid">;
5471-
def ext_template_arg_extra_parens : ExtWarn<
5472-
"address non-type template argument cannot be surrounded by parentheses">;
5473-
def warn_cxx98_compat_template_arg_extra_parens : Warning<
5474-
"redundant parentheses surrounding address non-type template argument are "
5475-
"incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;
54765393
def err_pointer_to_member_type : Error<
54775394
"invalid use of pointer to member type after %select{.*|->*}0">;
54785395
def err_pointer_to_member_call_drops_quals : Error<
@@ -5887,11 +5804,6 @@ def err_typename_missing_template
58875804
def ext_typename_missing
58885805
: ExtWarn<"missing 'typename' prior to dependent type name %0">,
58895806
InGroup<DiagGroup<"typename-missing">>;
5890-
def ext_typename_outside_of_template : ExtWarn<
5891-
"'typename' occurs outside of a template">, InGroup<CXX11>;
5892-
def warn_cxx98_compat_typename_outside_of_template : Warning<
5893-
"use of 'typename' outside of a template is incompatible with C++98">,
5894-
InGroup<CXX98Compat>, DefaultIgnore;
58955807
def err_typename_refers_to_using_value_decl : Error<
58965808
"typename specifier refers to a dependent using declaration for a value "
58975809
"%0 in %1">;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7648,8 +7648,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
76487648
// Only C++1y supports variable templates (N3651).
76497649
Diag(D.getIdentifierLoc(),
76507650
getLangOpts().CPlusPlus14
7651-
? diag::warn_cxx11_compat_variable_template
7652-
: diag::ext_variable_template);
7651+
? diag::compat_cxx14_variable_template
7652+
: diag::compat_pre_cxx14_variable_template);
76537653
}
76547654
}
76557655
} else {
@@ -7717,8 +7717,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
77177717
// the program is ill-formed. C++11 drops this restriction.
77187718
Diag(D.getIdentifierLoc(),
77197719
getLangOpts().CPlusPlus11
7720-
? diag::warn_cxx98_compat_static_data_member_in_union
7721-
: diag::ext_static_data_member_in_union)
7720+
? diag::compat_cxx11_static_data_member_in_union
7721+
: diag::compat_pre_cxx11_static_data_member_in_union)
77227722
<< Name;
77237723
}
77247724
}
@@ -7821,8 +7821,8 @@ NamedDecl *Sema::ActOnVariableDeclarator(
78217821
<< FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc());
78227822
} else {
78237823
Diag(D.getDeclSpec().getInlineSpecLoc(),
7824-
getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_inline_variable
7825-
: diag::ext_inline_variable);
7824+
getLangOpts().CPlusPlus17 ? diag::compat_cxx17_inline_variable
7825+
: diag::compat_pre_cxx17_inline_variable);
78267826
NewVD->setInlineSpecified();
78277827
}
78287828
}

0 commit comments

Comments
 (0)