Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang accepts declaration in a statement other than a compound statement #92775

Closed
AaronBallman opened this issue May 20, 2024 · 3 comments · Fixed by #92908
Closed

Clang accepts declaration in a statement other than a compound statement #92775

AaronBallman opened this issue May 20, 2024 · 3 comments · Fixed by #92908
Labels
accepts-invalid c clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party regression

Comments

@AaronBallman
Copy link
Collaborator

The following code is grammatically incorrect:

void func() {
  if (1)
    int x;
}

because an iteratation statement must be followed by a secondary-block, which is a kind of statement, which does not accept declarations accept as allowed by compound-statement. GCC properly rejects this code as did Clang 17, so this is a recent regression: https://godbolt.org/z/sj3de1T74

@llvmbot
Copy link
Member

llvmbot commented May 20, 2024

@llvm/issue-subscribers-c

Author: Aaron Ballman (AaronBallman)

The following code is grammatically incorrect: ``` void func() { if (1) int x; } ``` because an iteratation statement must be followed by a secondary-block, which is a kind of statement, which does not accept declarations accept as allowed by compound-statement. GCC properly rejects this code as did Clang 17, so this is a recent regression: https://godbolt.org/z/sj3de1T74

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label May 20, 2024
@llvmbot
Copy link
Member

llvmbot commented May 20, 2024

@llvm/issue-subscribers-clang-frontend

Author: Aaron Ballman (AaronBallman)

The following code is grammatically incorrect: ``` void func() { if (1) int x; } ``` because an iteratation statement must be followed by a secondary-block, which is a kind of statement, which does not accept declarations accept as allowed by compound-statement. GCC properly rejects this code as did Clang 17, so this is a recent regression: https://godbolt.org/z/sj3de1T74

@jrtc27
Copy link
Collaborator

jrtc27 commented May 20, 2024

Bisected to 8bd06d5, which seems plausible

AaronBallman added a commit that referenced this issue May 28, 2024
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 #92775
vg0204 pushed a commit to vg0204/llvm-project that referenced this issue May 29, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts-invalid c clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants