[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / typo-correction.c
blobceab0e2634c5c78a309df70e18a7d8fafb27aa5d
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 //
3 // This file contains typo correction tests which hit different code paths in C
4 // than in C++ and may exhibit different behavior as a result.
6 __typeof__(struct F*) var[invalid]; // expected-error-re {{use of undeclared identifier 'invalid'{{$}}}}
8 void PR21656(void) {
9 float x;
10 x = (float)arst; // expected-error-re {{use of undeclared identifier 'arst'{{$}}}}
13 a = b ? : 0; // expected-error {{type specifier missing, defaults to 'int'}} \
14 // expected-error {{use of undeclared identifier 'b'}}
16 int foobar; // expected-note {{'foobar' declared here}}
17 new_a = goobar ?: 4; // expected-error {{type specifier missing, defaults to 'int'}} \
18 // expected-error {{use of undeclared identifier 'goobar'; did you mean 'foobar'?}} \
19 // expected-error {{initializer element is not a compile-time constant}}
21 struct ContainerStuct {
22 enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}}
25 void func(int arg) {
26 switch (arg) {
27 case SOME_ENUM_: // expected-error {{use of undeclared identifier 'SOME_ENUM_'; did you mean 'SOME_ENUM'}}
32 void banana(void); // expected-note {{'banana' declared here}}
33 int c11Generic(int arg) {
34 _Generic(hello, int : banana)(); // expected-error-re {{use of undeclared identifier 'hello'{{$}}}}
35 _Generic(arg, int : bandana)(); // expected-error {{use of undeclared identifier 'bandana'; did you mean 'banana'?}}
38 typedef long long __m128i __attribute__((__vector_size__(16)));
39 int PR23101(__m128i __x) {
40 return foo((__v2di)__x); // expected-error {{call to undeclared function 'foo'; ISO C99 and later do not support implicit function declarations}} \
41 // expected-error {{use of undeclared identifier '__v2di'}}
44 void f(long *a, long b) {
45 __atomic_or_fetch(a, b, c); // expected-error {{use of undeclared identifier 'c'}}
48 extern double cabs(_Complex double z);
49 void fn1(void) {
50 cabs(errij); // expected-error {{use of undeclared identifier 'errij'}}
53 extern long afunction(int);
54 void fn2(void) {
55 f(THIS_IS_AN_ERROR, // expected-error {{use of undeclared identifier 'THIS_IS_AN_ERROR'}}
56 afunction(afunction_)); // expected-error {{use of undeclared identifier 'afunction_'}}
59 int d = X ? d : L; // expected-error 2 {{use of undeclared identifier}}
61 int fn_with_ids(void) { ID = ID == ID >= ID ; } // expected-error 4 {{use of undeclared identifier}}
63 int fn_with_rs(int r) { r = TYPO + r * TYPO; } // expected-error 2 {{use of undeclared identifier}}
65 void fn_with_unknown(int a, int b) {
66 fn_with_unknown(unknown, unknown | unknown); // expected-error 3 {{use of undeclared identifier}}
69 // Two typos in a parenthesized expression or argument list with a conditional
70 // expression caused a crash in C mode.
72 // r272587 fixed a similar bug for binary operations. The same fix was needed for
73 // conditional expressions.
75 int g(int x, int y) {
76 return x + y;
79 int h(void) {
80 g(x, 5 ? z : 0); // expected-error 2 {{use of undeclared identifier}}
81 (x, 5 ? z : 0); // expected-error 2 {{use of undeclared identifier}}
84 __attribute__((overloadable)) void func_overloadable(int);
85 __attribute__((overloadable)) void func_overloadable(float);
87 void overloadable_callexpr(int arg) {
88 func_overloadable(ar); //expected-error{{use of undeclared identifier}}
91 // rdar://problem/38642201
92 struct rdar38642201 {
93 int fieldName;
96 void rdar38642201_callee(int x, int y);
97 void rdar38642201_caller(void) {
98 struct rdar38642201 structVar;
99 rdar38642201_callee(
100 structVar1.fieldName1.member1, //expected-error{{use of undeclared identifier 'structVar1'}}
101 structVar2.fieldName2.member2); //expected-error{{use of undeclared identifier 'structVar2'}}
104 void PR40286_g(int x, int y);
105 void PR40286_h(int x, int y, int z);
106 void PR40286_1(int the_value) {
107 PR40286_g(the_walue); // expected-error {{use of undeclared identifier 'the_walue'}}
109 void PR40286_2(int the_value) {
110 PR40286_h(the_value, the_walue); // expected-error {{use of undeclared identifier 'the_walue'}}
112 void PR40286_3(int the_value) {
113 PR40286_h(the_walue); // expected-error {{use of undeclared identifier 'the_walue'}}
115 void PR40286_4(int the_value) { // expected-note {{'the_value' declared here}}
116 PR40286_h(the_value, the_value, the_walue); // expected-error {{use of undeclared identifier 'the_walue'; did you mean 'the_value'?}}