xref: /llvm-project/clang/test/Parser/compound-token-split.cpp (revision 113861b444610aebd1c05760a3e0ee6284f42211)
10e00a95bSRichard Smith // RUN: %clang_cc1 %s -verify
20e00a95bSRichard Smith // RUN: %clang_cc1 %s -verify=expected,space -Wcompound-token-split
30e00a95bSRichard Smith 
4*113861b4SRichard Smith // Ensure we get the same warnings after -frewrite-includes
5*113861b4SRichard Smith // RUN: %clang_cc1 %s -E -frewrite-includes -o %t
6*113861b4SRichard Smith // RUN: %clang_cc1 -x c++ %t -verify=expected,space -Wcompound-token-split
7*113861b4SRichard Smith 
80e00a95bSRichard Smith #ifdef LSQUARE
9*113861b4SRichard Smith [
100e00a95bSRichard Smith #else
110e00a95bSRichard Smith 
120e00a95bSRichard Smith #define VAR(type, name, init) type name = (init)
130e00a95bSRichard Smith 
140e00a95bSRichard Smith void f() {
150e00a95bSRichard Smith   VAR(int, x, {}); // #1
160e00a95bSRichard Smith   // expected-warning@#1 {{'(' and '{' tokens introducing statement expression appear in different macro expansion contexts}}
170e00a95bSRichard Smith   // expected-note-re@#1 {{{{^}}'{' token is here}}
180e00a95bSRichard Smith   //
190e00a95bSRichard Smith   // FIXME: It would be nice to suppress this when we already warned about the opening '({'.
200e00a95bSRichard Smith   // expected-warning@#1 {{'}' and ')' tokens terminating statement expression appear in different macro expansion contexts}}
210e00a95bSRichard Smith   // expected-note-re@#1 {{{{^}}')' token is here}}
220e00a95bSRichard Smith   //
230e00a95bSRichard Smith   // expected-error@#1 {{cannot initialize a variable of type 'int' with an rvalue of type 'void'}}
240e00a95bSRichard Smith }
250e00a95bSRichard Smith 
260e00a95bSRichard Smith #define RPAREN )
270e00a95bSRichard Smith 
280e00a95bSRichard Smith int f2() {
290e00a95bSRichard Smith   int n = ({ 1; }RPAREN; // expected-warning {{'}' and ')' tokens terminating statement expression appear in different macro expansion contexts}} expected-note {{')' token is here}}
300e00a95bSRichard Smith   return n;
310e00a95bSRichard Smith }
320e00a95bSRichard Smith 
33*113861b4SRichard Smith [ // space-warning-re {{{{^}}'[' tokens introducing attribute are separated by whitespace}}
340e00a95bSRichard Smith #define LSQUARE
350e00a95bSRichard Smith #include __FILE__
360e00a95bSRichard Smith   noreturn ]]  void g();
370e00a95bSRichard Smith 
380e00a95bSRichard Smith [[noreturn] ] void h(); // space-warning-re {{{{^}}']' tokens terminating attribute are separated by whitespace}}
390e00a95bSRichard Smith 
400e00a95bSRichard Smith struct X {};
410e00a95bSRichard Smith int X:: *p; // space-warning {{'::' and '*' tokens forming pointer to member type are separated by whitespace}}
420e00a95bSRichard Smith 
430e00a95bSRichard Smith #endif
44