Skip to content

Commit 30b67d4

Browse files
committed
Revert "[C23] Disable diagnostic on struct defn in prototype (llvm#138516)"
This reverts commit 15f7e02.
1 parent 0d413e5 commit 30b67d4

File tree

7 files changed

+14
-41
lines changed

7 files changed

+14
-41
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19526,10 +19526,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1952619526

1952719527
// If we're declaring or defining a tag in function prototype scope in C,
1952819528
// note that this type can only be used within the function and add it to
19529-
// the list of decls to inject into the function definition scope. However,
19530-
// in C23 and later, while the type is only visible within the function, the
19531-
// function can be called with a compatible type defined in the same TU, so
19532-
// we silence the diagnostic in C23 and up. This matches the behavior of GCC.
19529+
// the list of decls to inject into the function definition scope.
1953319530
if ((Name || Kind == TagTypeKind::Enum) &&
1953419531
getNonFieldDeclScope(S)->isFunctionPrototypeScope()) {
1953519532
if (getLangOpts().CPlusPlus) {
@@ -19543,10 +19540,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1954319540
if (TUK == TagUseKind::Declaration)
1954419541
Invalid = true;
1954519542
} else if (!PrevDecl) {
19546-
// In C23 mode, if the declaration is complete, we do not want to
19547-
// diagnose.
19548-
if (!getLangOpts().C23 || TUK != TagUseKind::Definition)
19549-
Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
19543+
Diag(Loc, diag::warn_decl_in_param_list) << Context.getTagDeclType(New);
1955019544
}
1955119545
}
1955219546

clang/test/C/C23/n3030.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static_assert(b == 1);
6161

6262
void f1(enum a : long b); // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
6363
// expected-warning@-1 {{declaration of 'enum a' will not be visible outside of this function}}
64-
void f2(enum c : long{x} d);
64+
void f2(enum c : long{x} d); // expected-warning {{declaration of 'enum c' will not be visible outside of this function}}
6565
enum e : int f3(); // expected-error {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
6666

6767
typedef enum t u; // expected-warning {{ISO C forbids forward references to 'enum' types}}

clang/test/C/drs/dr0xx.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only,c17andearlier -pedantic -Wno-declaration-after-statement -Wno-c11-extensions %s
2-
RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only,c17andearlier -pedantic -Wno-declaration-after-statement -Wno-c11-extensions -fno-signed-char %s
3-
RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=expected,c99untilc2x,c17andearlier -pedantic -Wno-c11-extensions %s
4-
RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x,c17andearlier -pedantic %s
5-
RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x,c17andearlier -pedantic %s
6-
RUN: %clang_cc1 -std=c23 -fsyntax-only -verify=expected,c2xandup -pedantic %s
1+
/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-declaration-after-statement -Wno-c11-extensions %s
2+
RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-declaration-after-statement -Wno-c11-extensions -fno-signed-char %s
3+
RUN: %clang_cc1 -std=c99 -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
4+
RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
5+
RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
6+
RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic %s
77
*/
88

99
/* The following are DRs which do not require tests to demonstrate
@@ -245,13 +245,13 @@ int dr032 = (1, 2); /* expected-warning {{left operand of comma operator has no
245245
* Questions about definition of functions without a prototype
246246
*/
247247
void dr035_1(a, b) /* expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}} */
248-
int a(enum b {x, y}); /* c17andearlier-warning {{declaration of 'enum b' will not be visible outside of this function}} */
248+
int a(enum b {x, y}); /* expected-warning {{declaration of 'enum b' will not be visible outside of this function}} */
249249
int b; {
250250
int test = x; /* expected-error {{use of undeclared identifier 'x'}} */
251251
}
252252

253253
void dr035_2(c) /* expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}} */
254-
enum m{q, r} c; { /* c17andearlier-warning {{declaration of 'enum m' will not be visible outside of this function}} */
254+
enum m{q, r} c; { /* expected-warning {{declaration of 'enum m' will not be visible outside of this function}} */
255255
/* FIXME: This should be accepted because the scope of m, q, and r ends at
256256
* the closing brace of the function per C89 6.1.2.1.
257257
*/

clang/test/C/drs/dr1xx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void dr103_2(struct S s) {} /* expected-warning {{declaration of 'struct S' will
107107
expected-note {{forward declaration of 'struct S'}} */
108108
void dr103_3(struct S s); /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
109109
expected-note {{previous declaration is here}} */
110-
void dr103_3(struct S { int a; } s) { } /* untilc23-warning {{declaration of 'struct S' will not be visible outside of this function}}
110+
void dr103_3(struct S { int a; } s) { } /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}}
111111
expected-error {{conflicting types for 'dr103_3'}} */
112112
void dr103_4(struct S s1, struct S { int a; } s2); /* expected-warning {{declaration of 'struct S' will not be visible outside of this function}} */
113113

clang/test/Sema/c23-decl-in-prototype.c

Lines changed: 0 additions & 21 deletions
This file was deleted.

clang/test/Sema/decl-in-prototype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c17 %s
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
22

33
#define SA(n, c) int arr##n[(c) ? 1 : -1] = {}
44

clang/test/Sema/enum.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void PR8694(int* e) // expected-note {{passing argument to parameter 'e' here}}
108108
{
109109
}
110110

111-
void crash(enum E *e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \
111+
void crash(enum E* e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \
112112
// expected-warning {{ISO C forbids forward references to 'enum' types}}
113113
{
114114
PR8694(e); // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}}

0 commit comments

Comments
 (0)