Skip to content

Commit c6a0b3f

Browse files
committed
Update based on review feedback; fix tests
1 parent 5271b8b commit c6a0b3f

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

clang-tools-extra/clangd/IncludeFixer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
8484
case diag::err_array_incomplete_or_sizeless_type:
8585
case diag::err_array_size_incomplete_type:
8686
case diag::err_asm_incomplete_type:
87-
case diag::err_assoc_type_incomplete:
8887
case diag::err_bad_cast_incomplete:
8988
case diag::err_call_function_incomplete_return:
9089
case diag::err_call_incomplete_argument:

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10426,11 +10426,11 @@ def warn_type_safety_null_pointer_required : Warning<
1042610426

1042710427
// Generic selections.
1042810428
def ext_assoc_type_incomplete : Extension<
10429-
"ISO C requires a complete type in a '_Generic' association; %0 is an "
10430-
"incomplete type">;
10429+
"incomplete type %0 in a '_Generic' association is a C2y extension">,
10430+
InGroup<C2y>;
1043110431
def warn_c2y_compat_assoc_type_incomplete : Warning<
10432-
"use of an incomplete type in a '_Generic' association is incompatible with "
10433-
"C standards before C2y; %0 is an incomplete type">,
10432+
"use of incomplete type %0 in a '_Generic' association is incompatible with "
10433+
"C standards before C2y">,
1043410434
InGroup<CPre2yCompat>, DefaultIgnore;
1043510435
def err_assoc_type_nonobject : Error<
1043610436
"type %0 in generic association not an object type">;

clang/lib/Sema/SemaStmt.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,11 +2269,10 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
22692269
for (auto *DI : DS->decls()) {
22702270
if (VarDecl *VD = dyn_cast<VarDecl>(DI)) {
22712271
VarDeclSeen = true;
2272-
if (VD->isLocalVarDecl() && !VD->hasLocalStorage())
2273-
Diag(DI->getLocation(),
2274-
getLangOpts().C23
2275-
? diag::warn_c17_non_local_variable_decl_in_for
2276-
: diag::ext_c23_non_local_variable_decl_in_for);
2272+
if (VD->isLocalVarDecl() && !VD->hasLocalStorage()) {
2273+
Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
2274+
DI->setInvalidDecl();
2275+
}
22772276
} else if (!NonVarSeen) {
22782277
// Keep track of the first non-variable declaration we saw so that
22792278
// we can diagnose if we don't see any variable declarations. This
@@ -2285,9 +2284,7 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
22852284
// Diagnose if we saw a non-variable declaration but no variable
22862285
// declarations.
22872286
if (NonVarSeen && !VarDeclSeen)
2288-
Diag(NonVarSeen->getLocation(),
2289-
getLangOpts().C23 ? diag::warn_c17_non_variable_decl_in_for
2290-
: diag::ext_c23_non_variable_decl_in_for);
2287+
Diag(NonVarSeen->getLocation(), diag::err_non_variable_decl_in_for);
22912288
}
22922289
}
22932290

@@ -4052,9 +4049,9 @@ StmtResult Sema::BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
40524049
Diag(ReturnLoc, D) << CurDecl << isa<CXXDestructorDecl>(CurDecl)
40534050
<< RetValExp->getSourceRange();
40544051
}
4055-
// return (some void expression); is legal in C++.
4052+
// return (some void expression); is legal in C++ and C2y.
40564053
else if (D != diag::ext_return_has_void_expr ||
4057-
!getLangOpts().CPlusPlus) {
4054+
(!getLangOpts().CPlusPlus && !getLangOpts().C2y)) {
40584055
NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
40594056

40604057
int FunctionKind = 0;

clang/test/C/C2y/n3409.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ void foo() {
1919
(void)(void)1;
2020
// FIXME: same with this.
2121
x;
22-
_Generic(x, void: 1); /* pre-c2y-warning {{use of an incomplete type in a '_Generic' association is incompatible with C standards before C2y; 'void' is an incomplete type}}
23-
ext-warning {{ISO C requires a complete type in a '_Generic' association; 'void' is an incomplete type}}
22+
_Generic(x, void: 1); /* pre-c2y-warning {{use of incomplete type 'void' in a '_Generic' association is incompatible with C standards before C2y}}
23+
ext-warning {{incomplete type 'void' in a '_Generic' association is a C2y extension}}
2424
*/
25-
_Generic(x, typeof(x): 1); /* pre-c2y-warning {{use of an incomplete type in a '_Generic' association is incompatible with C standards before C2y; 'typeof (x)' (aka 'void') is an incomplete type}}
26-
ext-warning {{ISO C requires a complete type in a '_Generic' association; 'typeof (x)' (aka 'void') is an incomplete type}}
25+
_Generic(x, typeof(x): 1); /* pre-c2y-warning {{use of incomplete type 'typeof (x)' (aka 'void') in a '_Generic' association is incompatible with C standards before C2y}}
26+
ext-warning {{incomplete type 'typeof (x)' (aka 'void') in a '_Generic' association is a C2y extension}}
2727
*/
2828
(void)_Generic(void, default : 1); /* pre-c2y-warning {{passing a type argument as the first operand to '_Generic' is incompatible with C standards before C2y}}
2929
ext-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
3030
*/
31-
}
3231

32+
// This is not sufficiently important of an extension to warrant a "not
33+
// compatible with standards before C2y" warning, but it is an extension in
34+
// C23 and earlier.
35+
return x; // ext-warning {{void function 'foo' should not return void expression}}
36+
}

clang/test/Sema/generic-selection-type-extension.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static_assert(_Generic(ci, int : 1, const int : 0) == 1); // expected-warning {{
3737
// but the expression operand form still rejects them.
3838
static_assert(_Generic(struct incomplete, struct incomplete : 1, default : 0) == 1);
3939
static_assert(_Generic(struct another_incomplete, struct incomplete : 1, default : 0) == 0);
40-
static_assert(_Generic(1, struct also_incomplete : 1, default : 0) == 0); // expected-error {{type 'struct also_incomplete' in generic association incomplete}}
40+
static_assert(_Generic(1, struct also_incomplete : 1, default : 0) == 0);
4141

4242
void foo(int);
4343
static_assert(_Generic(__typeof__(foo), void(int) : 1, default : 0) == 1);

clang/test/Sema/generic-selection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void g(void);
55

66
void foo(int n) {
77
(void) _Generic(0, // ext-warning {{'_Generic' is a C11 extension}}
8-
struct A: 0, // expected-error {{type 'struct A' in generic association incomplete}}
8+
struct A: 0, // ext-warning {{incomplete type 'struct A' in a '_Generic' association is a C2y extension}}
99
void(): 0, // expected-error {{type 'void ()' in generic association not an object type}}
1010
int[n]: 0); // expected-error {{type 'int[n]' in generic association is a variably modified type}}
1111

clang/test/SemaCXX/generic-selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ void func(struct S s) {
8181
// is an elaborated type specifier followed by the association's value and
8282
// it should work the same as in C.
8383
(void)_Generic(s, struct S : 1);
84+
(void)_Generic(s, struct T : 1);
8485

8586
// The rest of these cases test that we still produce a reasonable diagnostic
8687
// when referencing an unknown type or trying to define a type in other ways.
87-
(void)_Generic(s, struct T : 1); // expected-error {{type 'struct T' in generic association incomplete}}
8888
(void)_Generic(s, struct U { int a; } : 1); // expected-error {{'U' cannot be defined in a type specifier}}
8989
(void)_Generic(s, struct V : S); // expected-error {{'S' does not refer to a value}}
9090
(void)_Generic(s, struct W : S { int b; } : 1); // expected-error {{expected '(' for function-style cast or type construction}}

0 commit comments

Comments
 (0)