llvm-project
llvm-project copied to clipboard
[C++] accepts-invalid: Clang incorrectly accepts attribute missing closing `]]` when followed by `;;`
Clang accepts ill-formed C++ code where an attribute block is opened with [[ but closed with ;; instead of ]].
Reproducer on Compiler Explorer: https://godbolt.org/z/M7W9o11se
(Since x86-64 clang 13.0.0)
Code:
// weird.cpp
void a() {
[[assume0;;
}
$ clang --version
clang version 23.0.0git (https://github.com/llvm/llvm-project.git f1b16eaeddbbcc8239ad454309779d42adcfe4f1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/lenovo/lenovo/compiler-build/llvm-project/build/bin
Build config: +assertions
$ # This behavior appears since clang 13.0.0
$ clang -S weird.cpp
weird.cpp:2:5: warning: unknown attribute 'assume0' ignored [-Wunknown-attributes]
2 | [[assume0;;
| ^~~~~~~
1 warning generated.
$ gcc -S weird.cpp
weird.cpp: In function ‘void a()’:
weird.cpp:2:12: error: expected ‘]’ before ‘;’ token
2 | [[assume0;;
| ^
| ]
weird.cpp:2:3: warning: attributes at the beginning of statement are ignored [-Wattributes]
2 | [[assume0;;
| ^~~~~~~~~
@a-tarasyuk
@llvm/issue-subscribers-clang-frontend
Author: None (thapgua)
Clang accepts ill-formed C++ code where an attribute block is opened with `[[` but closed with `;;` instead of `]]`.
Reproducer on Compiler Explorer: https://godbolt.org/z/M7W9o11se
(Since x86-64 clang 13.0.0)
Code:
// weird.cpp
void a() {
[[assume0;;
}
$ clang --version
clang version 23.0.0git (https://github.com/llvm/llvm-project.git f1b16eaeddbbcc8239ad454309779d42adcfe4f1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/lenovo/lenovo/compiler-build/llvm-project/build/bin
Build config: +assertions
$ # This behavior appears since clang 13.0.0
$ clang -S weird.cpp
weird.cpp:2:5: warning: unknown attribute 'assume0' ignored [-Wunknown-attributes]
2 | [[assume0;;
| ^~~~~~~
1 warning generated.
$ gcc -S weird.cpp
weird.cpp: In function ‘void a()’:
weird.cpp:2:12: error: expected ‘]’ before ‘;’ token
2 | [[assume0;;
| ^
| ]
weird.cpp:2:3: warning: attributes at the beginning of statement are ignored [-Wattributes]
2 | [[assume0;;
| ^~~~~~~~~
I would like to work on it 😋