forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C] Disallow declarations where a statement is required (llvm#92908)
This fixes a regression introduced in 8bd06d5 where Clang began to accept a declaration where a statement is required. e.g., ``` if (1) int x; // Previously accepted, now properly rejected ``` Fixes llvm#92775
- Loading branch information
1 parent
d33864d
commit 5901d40
Showing
6 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic | ||
|
||
// Test that we can parse declarations at global scope. | ||
int v; | ||
|
||
void func(void) { | ||
// Test that we can parse declarations within a compound statement. | ||
int a; | ||
{ | ||
int b; | ||
} | ||
|
||
int z = ({ // expected-warning {{use of GNU statement expression extension}} | ||
// Test that we can parse declarations within a GNU statement expression. | ||
int w = 12; | ||
w; | ||
}); | ||
|
||
// Test that we diagnose declarations where a statement is required. | ||
// See GH92775. | ||
if (1) | ||
int x; // expected-error {{expected expression}} | ||
for (;;) | ||
int c; // expected-error {{expected expression}} | ||
|
||
label: | ||
int y; // expected-warning {{label followed by a declaration is a C23 extension}} | ||
|
||
// Test that lookup works as expected. | ||
(void)a; | ||
(void)v; | ||
(void)z; | ||
(void)b; // expected-error {{use of undeclared identifier 'b'}} | ||
(void)w; // expected-error {{use of undeclared identifier 'w'}} | ||
(void)x; // expected-error {{use of undeclared identifier 'x'}} | ||
(void)c; // expected-error {{use of undeclared identifier 'c'}} | ||
(void)y; | ||
} | ||
|
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