Clang Project

clang_source_code/test/Sema/typo-correction.c
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.
5
6__typeof__(struct F*) var[invalid];  // expected-error-re {{use of undeclared identifier 'invalid'{{$}}}}
7
8void PR21656() {
9  float x;
10  x = (float)arst;  // expected-error-re {{use of undeclared identifier 'arst'{{$}}}}
11}
12
13a = b ? : 0;  // expected-warning {{type specifier missing, defaults to 'int'}} \
14              // expected-error {{use of undeclared identifier 'b'}}
15
16int foobar;  // expected-note {{'foobar' declared here}}
17a = goobar ?: 4;  // expected-warning {{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}}
20
21struct ContainerStuct {
22  enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}}
23};
24
25void func(int arg) {
26  switch (arg) {
27  case SOME_ENUM_: // expected-error {{use of undeclared identifier 'SOME_ENUM_'; did you mean 'SOME_ENUM'}}
28    ;
29  }
30}
31
32void banana(void);  // expected-note {{'banana' declared here}}
33int 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'?}}
36}
37
38typedef long long __m128i __attribute__((__vector_size__(16)));
39int PR23101(__m128i __x) {
40  return foo((__v2di)__x);  // expected-warning {{implicit declaration of function 'foo'}} \
41                            // expected-error {{use of undeclared identifier '__v2di'}}
42}
43
44void f(long *a, long b) {
45      __atomic_or_fetch(a, b, c);  // expected-error {{use of undeclared identifier 'c'}}
46}
47
48extern double cabs(_Complex double z);
49void fn1() {
50  cabs(errij);  // expected-error {{use of undeclared identifier 'errij'}}
51}
52
53extern long afunction(int); // expected-note {{'afunction' declared here}}
54void fn2() {
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_'; did you mean 'afunction'?}}
57}
58
59int d = X ? d : L; // expected-error 2 {{use of undeclared identifier}}
60
61int fn_with_ids() { ID = ID == ID >= ID ; } // expected-error 4 {{use of undeclared identifier}}
62
63int fn_with_rs(int r) { r = TYPO + r * TYPO; } // expected-error 2 {{use of undeclared identifier}}
64
65void fn_with_unknown(int a, int b) {
66  fn_with_unknown(unknown, unknown | unknown); // expected-error 3 {{use of undeclared identifier}}
67}
68
69// Two typos in a parenthesized expression or argument list with a conditional
70// expression caused a crash in C mode.
71//
72// r272587 fixed a similar bug for binary operations. The same fix was needed for
73// conditional expressions.
74
75int g(int x, int y) {
76  return x + y;
77}
78
79int h() {
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}}
82}
83
84__attribute__((overloadable)) void func_overloadable(int);
85__attribute__((overloadable)) void func_overloadable(float);
86
87void overloadable_callexpr(int arg) {
88 func_overloadable(ar); //expected-error{{use of undeclared identifier}}
89}
90
91// rdar://problem/38642201
92struct rdar38642201 {
93  int fieldName;
94};
95
96void rdar38642201_callee(int x, int y);
97void rdar38642201_caller() {
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'}}
102}
103
104void PR40286_g(int x, int y);
105void PR40286_h(int x, int y, int z);
106void PR40286_1(int the_value) {
107  PR40286_g(the_walue); // expected-error {{use of undeclared identifier 'the_walue'}}
108}
109void PR40286_2(int the_value) {
110  PR40286_h(the_value, the_walue); // expected-error {{use of undeclared identifier 'the_walue'}}
111}
112void PR40286_3(int the_value) {
113  PR40286_h(the_walue); // expected-error {{use of undeclared identifier 'the_walue'}}
114}
115void 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'?}}
117}
118