110 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code2// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s -Wno-unreachable-code3 4void test1(void) {5 { ; { ;;}} ;;6}7 8void test2(void) {9 if (0) { if (1) {} } else { }10 11 do { } while (0); 12 13 while (0) while(0) do ; while(0);14 15 for ((void)0;0;(void)0)16 for (;;)17 for ((void)9;0;(void)2)18 ;19 for (int X = 0; 0; (void)0);20}21 22void test3(void) {23 switch (0) {24 25 case 4:26 if (0) {27 case 6: ;28 }29 default:30 ; 31 }32}33 34void test4(void) {35 if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}36 37 int X; // declaration in a block.38 39foo: if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}40}41 42typedef int t;43void test5(void) {44 if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}45 46 t x = 0;47 48 if (0); // expected-warning {{if statement has empty body}} expected-note {{put the semicolon on a separate line to silence this warning}}49}50 51 52void test6(void) { 53 do 54 . // expected-error {{expected expression}}55 while (0);56}57 58int test7(void) {59 return 4 // expected-error {{expected ';' after return statement}}60}61 62void test8(void) {63 // Should not skip '}' and produce a "expected '}'" error.64 undecl // expected-error {{use of undeclared identifier 'undecl'}}65}66 67int test9(void) {68 int T[] = {1, 2, };69 70 int X;71 X = 0, // expected-error {{expected ';' after expression}}72 {73 }74 75 X = 0, // expected-error {{expected ';' after expression}}76 if (0)77 ;78 79 return 4, // expected-error {{expected ';' after return statement}}80}81 82#if __STDC_VERSION__ >= 202311L83void attr_decl_in_selection_statement(int n) {84 if (1)85 [[]]; // expected-warning {{ISO C does not allow an attribute list to appear here}}86 87 if (1) {88 89 } else90 [[]]; // expected-warning {{ISO C does not allow an attribute list to appear here}}91 92 93 switch (n)94 [[]]; // expected-warning {{ISO C does not allow an attribute list to appear here}}95}96 97void attr_decl_in_iteration_statement(int n) {98 int i;99 for (i = 0; i < n; ++i)100 [[]]; // expected-warning {{ISO C does not allow an attribute list to appear here}}101 102 while (i > 0)103 [[]]; // expected-warning {{ISO C does not allow an attribute list to appear here}}104 105 do106 [[]]; // expected-warning {{ISO C does not allow an attribute list to appear here}}107 while (i > 0);108}109#endif // __STDC_VERSION__ >= 202311L110