[C2y] Modify diagnostics for generic selection with a type operand
We implemented WG14 N3260 as an extension, now it's a feature of C2y.
This commit is contained in:
parent
380beaec86
commit
efefee28a4
@ -299,6 +299,10 @@ def CPre23CompatPedantic : DiagGroup<"pre-c23-compat-pedantic",
|
||||
def : DiagGroup<"pre-c2x-compat", [CPre23Compat]>;
|
||||
def : DiagGroup<"pre-c2x-compat-pedantic", [CPre23CompatPedantic]>;
|
||||
|
||||
def CPre2yCompat : DiagGroup<"pre-c2y-compat">;
|
||||
def CPre2yCompatPedantic : DiagGroup<"pre-c2y-compat-pedantic",
|
||||
[CPre2yCompat]>;
|
||||
|
||||
// Warnings for C++ code which is not compatible with previous C++ standards.
|
||||
def CXXPre14Compat : DiagGroup<"pre-c++14-compat">;
|
||||
def : DiagGroup<"c++98-c++11-compat", [CXXPre14Compat]>;
|
||||
@ -1197,6 +1201,9 @@ def C23 : DiagGroup<"c23-extensions">;
|
||||
|
||||
def : DiagGroup<"c2x-extensions", [C23]>;
|
||||
|
||||
// A warning group for warnings about using C2y features as extensions.
|
||||
def C2y : DiagGroup<"c2y-extensions">;
|
||||
|
||||
// Previously supported warning group which is no longer pertinent as binary
|
||||
// literals are a C++14 and C23 extension now instead of a GNU extension.
|
||||
def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;
|
||||
|
||||
@ -157,9 +157,12 @@ def err_duplicate_default_assoc : Error<
|
||||
"duplicate default generic association">;
|
||||
def note_previous_default_assoc : Note<
|
||||
"previous default generic association is here">;
|
||||
def ext_generic_with_type_arg : Extension<
|
||||
"passing a type argument as the first operand to '_Generic' is a Clang "
|
||||
"extension">, InGroup<DiagGroup<"generic-type-extension">>;
|
||||
def ext_c2y_generic_with_type_arg : Extension<
|
||||
"passing a type argument as the first operand to '_Generic' is a C2y "
|
||||
"extension">, InGroup<C2y>;
|
||||
def warn_c2y_compat_generic_with_type_arg : Warning<
|
||||
"passing a type argument as the first operand to '_Generic' is incompatible "
|
||||
"with C standards before C2y">, InGroup<CPre2yCompat>, DefaultIgnore;
|
||||
|
||||
def ext_c99_feature : Extension<
|
||||
"'%0' is a C99 extension">, InGroup<C99>;
|
||||
|
||||
@ -3449,7 +3449,8 @@ ExprResult Parser::ParseGenericSelectionExpression() {
|
||||
}
|
||||
const auto *LIT = cast<LocInfoType>(ControllingType.get().get());
|
||||
SourceLocation Loc = LIT->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
|
||||
Diag(Loc, diag::ext_generic_with_type_arg);
|
||||
Diag(Loc, getLangOpts().C2y ? diag::warn_c2y_compat_generic_with_type_arg
|
||||
: diag::ext_c2y_generic_with_type_arg);
|
||||
} else {
|
||||
// C11 6.5.1.1p3 "The controlling expression of a generic selection is
|
||||
// not evaluated."
|
||||
|
||||
16
clang/test/C/C2y/n3260.c
Normal file
16
clang/test/C/C2y/n3260.c
Normal file
@ -0,0 +1,16 @@
|
||||
// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -Wpre-c2y-compat %s
|
||||
// RUN: %clang_cc1 -verify=pre-c2y -std=c23 -Wall -pedantic %s
|
||||
|
||||
/* WG14 N3260: Clang 17
|
||||
* Generic selection expression with a type operand
|
||||
*/
|
||||
|
||||
static_assert(
|
||||
_Generic(
|
||||
const int, /* pre-c2y-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
|
||||
expected-warning {{passing a type argument as the first operand to '_Generic' is incompatible with C standards before C2y}}
|
||||
*/
|
||||
int : 0,
|
||||
const int : 1
|
||||
)
|
||||
);
|
||||
@ -4,7 +4,7 @@
|
||||
// in the right location.
|
||||
void test(void) {
|
||||
(void)_Generic(
|
||||
int, // expected-warning {{passing a type argument as the first operand to '_Generic' is a Clang extension}}
|
||||
int, // expected-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
|
||||
int : 0);
|
||||
(void)_Generic(
|
||||
12,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user