llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[C++] accepts-invalid: Clang incorrectly accepts attribute missing closing `]]` when followed by `;;`

Open thapgua opened this issue 8 months ago • 3 comments

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;;
      |   ^~~~~~~~~

thapgua avatar Mar 18 '26 09:03 thapgua

@a-tarasyuk

zyn0217 avatar Mar 18 '26 09:03 zyn0217

@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;;
      |   ^~~~~~~~~

llvmbot avatar Mar 18 '26 09:03 llvmbot

I would like to work on it 😋

AmrDeveloper avatar Mar 19 '26 20:03 AmrDeveloper