97 lines · c
1// RUN: %clang_cc1 -pedantic -Wunused-label -Wno-deprecated-non-prototype -verify -x c %s2// RUN: cp %s %t3// RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t4// RUN: %clang_cc1 -pedantic -Wunused-label -Wno-deprecated-non-prototype -Werror -x c %t5// RUN: grep -v CHECK %t | FileCheck %t6 7/* This is a test of the various code modification hints that are8 provided as part of warning or extension diagnostics. All of the9 warnings will be fixed by -fixit, and the resulting file should10 compile cleanly with -Werror -pedantic. */11 12// FIXME: FIX-IT should add #include <string.h>?13int strcmp(const char *s1, const char *s2);14 15void f0(void) { }; // expected-warning {{';'}}16 17struct s {18 int x, y;; // expected-warning {{extra ';'}}19};20 21// CHECK: _Complex double cd;22_Complex cd; // expected-warning {{assuming '_Complex double'}}23 24// CHECK: struct s s0 = { .y = 5 };25struct s s0 = { y: 5 }; // expected-warning {{GNU old-style}}26 27// CHECK: int array0[5] = { [3] = 3 };28int array0[5] = { [3] 3 }; // expected-warning {{GNU 'missing ='}}29 30// CHECK: int x31// CHECK: int y32void f1(x, y) // expected-error 2{{was not declared, defaults to 'int'; ISO C99 and later do not support implicit int}}33{34}35 36int i0 = { 17 };37 38#define ONE 139#define TWO 240 41int test_cond(int y, int fooBar) { // expected-note {{here}}42// CHECK: int x = y ? 1 : 4+fooBar;43 int x = y ? 1 4+foobar; // expected-error {{expected ':'}} expected-error {{undeclared identifier}} expected-note {{to match}}44// CHECK: x = y ? ONE : TWO;45 x = y ? ONE TWO; // expected-error {{':'}} expected-note {{to match}}46 return x;47}48 49// CHECK: const typedef int int_t;50const typedef typedef int int_t; // expected-warning {{duplicate 'typedef'}}51 52enum Color {53 Red // expected-error{{missing ',' between enumerators}}54 Green = 17 // expected-error{{missing ',' between enumerators}}55 Blue,56};57 58struct test_struct {59 // CHECK: struct test_struct *struct_ptr;60 test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}}61};62 63void removeUnusedLabels(char c) {64 L0 /*removed comment*/: c++; // expected-warning {{unused label}}65 removeUnusedLabels(c);66 L1: // expected-warning {{unused label}}67 c++;68 /*preserved comment*/ L2 : c++; // expected-warning {{unused label}}69 LL // expected-warning {{unused label}}70 : c++;71 c = c + 3; L4: return; // expected-warning {{unused label}}72}73 74int oopsAComma = 0, // expected-error {{';'}}75void oopsMoreCommas(void) {76 static int a[] = { 0, 1, 2 }, // expected-error {{';'}}77 static int b[] = { 3, 4, 5 }, // expected-error {{';'}}78 &a == &b ? oopsMoreCommas() : removeUnusedLabels(a[0]);79}80 81int commaAtEndOfStatement(void) {82 int a = 1;83 a = 5, // expected-error {{';'}}84 int m = 5, // expected-error {{';'}}85 return 0, // expected-error {{';'}}86}87 88struct noSemiAfterStruct // expected-error {{expected ';' after struct}}89struct noSemiAfterStruct {90 int n // expected-warning {{';'}}91} // expected-error {{expected ';' after struct}}92enum noSemiAfterEnum {93 e194} // expected-error {{expected ';' after enum}}95 96int PR17175 __attribute__((visibility(hidden))); // expected-error {{'visibility' attribute requires a string}}97