llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.71k stars 10.94k forks source link

[Clang] Possible bug with labels at the end of compound statements in C #58632

Closed OCHyams closed 1 year ago

OCHyams commented 1 year ago

With this test case test.c:

void fun(void) {
label:
}

Before D133887 we got an error:

$ clang label.c -c -std=c17
label.c:3:1: error: expected statement
}
^
1 error generated.

With D133887 we just get a warning:

$ clang label.c -c -std=c17
label.c:3:1: warning: label at end of compound statement is a C2x extension [-Wc2x-extensions]
}
^
1 warning generated.

I'm not very familiar with the C standard but it seemed suspicious that this error has become a warning even though -std=c17 is specified in the example. Is this a bug?

Also see on compiler explorer with clang-15 vs trunk.

cc @cor3ntin and @Izaron from D133887.

llvmbot commented 1 year ago

@llvm/issue-subscribers-c

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

Izaron commented 1 year ago

Hi! This isn't a bug, it's a C++2b (tentatively C++23) and C2x (tentatively C23) feature: https://github.com/cplusplus/papers/issues/1006

even though -std=c17 is specified in the example

Clang backports most of the features of more recent standards to all possible standards (with warnings) if it doesn't break important things.

If you want to forbid backporting features of the more recent standard, you can use -Werror=c2x-extensions flag

AaronBallman commented 1 year ago

This behavior is by design, closing as not a bug.

OCHyams commented 1 year ago

Ok, thanks for the info!

AaronBallman commented 1 year ago

Btw, the reference to the C paper for this feature is: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf