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

_Static_assert not accepted in empty switch/case clause #69572

Closed
joeyye-work opened this issue Oct 19, 2023 · 3 comments
Closed

_Static_assert not accepted in empty switch/case clause #69572

joeyye-work opened this issue Oct 19, 2023 · 3 comments
Labels
c11 clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate rejects-valid

Comments

@joeyye-work
Copy link
Contributor

joeyye-work commented Oct 19, 2023

#include <assert.h>
int main(int x, char **argv)
{
        switch (x) {
                case 1:
                    // x++;  // Uncommenting this will pass
                    _Static_assert(1, "error message");
                    break;
        };
        return x;
}

compiled with clang -c c.c -std=c11
error: expected expression
_Static_assert(1, "error message");

Impacted version: from llvm-14 to llvm-17

Strange thing is if I put some statements before the _Static_assert it will work.

GCC compiles it fine.

@dtcxzyw dtcxzyw added clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid and removed new issue labels Oct 19, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 19, 2023

@llvm/issue-subscribers-clang-frontend

Author: Jinyun (Joey) Ye (joeyye-work)

```c #include <assert.h> int main(int x, char **argv) { switch (x) { case 1: // x++; // Uncommenting this will pass _Static_assert(1, "error message"); break; }; return x; } ``` compiled with clang -c c.c -std=c11 error: expected expression _Static_assert(1, "error message");

Impacted version: from llvm-14 to llvm-17

Strange thing is if I put some statements before the _Static_assert it will work.

GCC compiles it fine.

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 19, 2023

@llvm/issue-subscribers-c11

Author: Jinyun (Joey) Ye (joeyye-work)

```c #include <assert.h> int main(int x, char **argv) { switch (x) { case 1: // x++; // Uncommenting this will pass _Static_assert(1, "error message"); break; }; return x; } ``` compiled with clang -c c.c -std=c11 error: expected expression _Static_assert(1, "error message");

Impacted version: from llvm-14 to llvm-17

Strange thing is if I put some statements before the _Static_assert it will work.

GCC compiles it fine.

@AaronBallman
Copy link
Collaborator

This isn't valid until C23 because _Static_assert is a declaration, not a statement; we partially implement WG14 N2508 but we don't fully implement it. This is a duplicate of #53692

@AaronBallman AaronBallman closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2023
@AaronBallman AaronBallman added the duplicate Resolved as duplicate label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c11 clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate rejects-valid
Projects
None yet
Development

No branches or pull requests

5 participants