[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / typo-correction-delayed.cpp
blobfdb1f740fda6a46e6944775746a17e7f0828c260
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wno-c++11-extensions %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
5 struct A {};
6 struct B {};
7 struct D {
8 A fizbin; // expected-note 2 {{declared here}}
9 A foobar; // expected-note 2 {{declared here}}
10 B roxbin; // expected-note 2 {{declared here}}
11 B toobad; // expected-note 2 {{declared here}}
12 void BooHoo();
13 void FoxBox();
16 void something(A, B);
17 void test() {
18 D obj;
19 something(obj.fixbin, // expected-error {{did you mean 'fizbin'?}}
20 obj.toobat); // expected-error {{did you mean 'toobad'?}}
21 something(obj.toobat, // expected-error {{did you mean 'foobar'?}}
22 obj.fixbin); // expected-error {{did you mean 'roxbin'?}}
23 something(obj.fixbin, // expected-error {{did you mean 'fizbin'?}}
24 obj.fixbin); // expected-error {{did you mean 'roxbin'?}}
25 something(obj.toobat, // expected-error {{did you mean 'foobar'?}}
26 obj.toobat); // expected-error {{did you mean 'toobad'?}}
27 // Both members could be corrected to methods, but that isn't valid.
28 something(obj.boohoo, // expected-error-re {{no member named 'boohoo' in 'D'{{$}}}}
29 obj.foxbox); // expected-error-re {{no member named 'foxbox' in 'D'{{$}}}}
30 // The first argument has a usable correction but the second doesn't.
31 something(obj.boobar, // expected-error-re {{no member named 'boobar' in 'D'{{$}}}}
32 obj.foxbox); // expected-error-re {{no member named 'foxbox' in 'D'{{$}}}}
35 // Ensure the delayed typo correction does the right thing when trying to
36 // recover using a seemingly-valid correction for which a valid expression to
37 // replace the TypoExpr cannot be created (but which does have a second
38 // correction candidate that would be a valid and usable correction).
39 class Foo {
40 public:
41 template <> void testIt(); // expected-error {{no function template matches}}
42 void textIt(); // expected-note {{'textIt' declared here}}
44 void testMemberExpr(Foo *f) {
45 f->TestIt(); // expected-error {{no member named 'TestIt' in 'Foo'; did you mean 'textIt'?}}
48 void callee(double, double);
49 void testNoCandidates() {
50 callee(xxxxxx, // expected-error-re {{use of undeclared identifier 'xxxxxx'{{$}}}}
51 zzzzzz); // expected-error-re {{use of undeclared identifier 'zzzzzz'{{$}}}}
54 class string {};
55 struct Item {
56 void Nest();
57 string text();
58 Item* next(); // expected-note {{'next' declared here}}
60 void testExprFilter(Item *i) {
61 Item *j;
62 j = i->Next(); // expected-error {{no member named 'Next' in 'Item'; did you mean 'next'?}}
65 // Test that initializer expressions are handled correctly and that the type
66 // being initialized is taken into account when choosing a correction.
67 namespace initializerCorrections {
68 struct Node {
69 string text() const;
70 // Node* Next() is not implemented yet
72 void f(Node *node) {
73 // text is only an edit distance of 1 from Next, but would trigger type
74 // conversion errors if used in this initialization expression.
75 Node *next = node->Next(); // expected-error-re {{no member named 'Next' in 'initializerCorrections::Node'{{$}}}}
78 struct LinkedNode {
79 LinkedNode* next(); // expected-note {{'next' declared here}}
80 string text() const;
82 void f(LinkedNode *node) {
83 // text and next are equidistant from Next, but only one results in a valid
84 // initialization expression.
85 LinkedNode *next = node->Next(); // expected-error {{no member named 'Next' in 'initializerCorrections::LinkedNode'; did you mean 'next'?}}
88 struct NestedNode {
89 NestedNode* Nest();
90 NestedNode* next();
91 string text() const;
93 void f(NestedNode *node) {
94 // There are two equidistant, usable corrections for Next: next and Nest
95 NestedNode *next = node->Next(); // expected-error-re {{no member named 'Next' in 'initializerCorrections::NestedNode'{{$}}}}
99 namespace PR21669 {
100 void f(int *i) {
101 // Check that arguments to a builtin with custom type checking are corrected
102 // properly, since calls to such builtins bypass much of the normal code path
103 // for building and checking the call.
104 __atomic_load(i, i, something_something); // expected-error-re {{use of undeclared identifier 'something_something'{{$}}}}
108 const int DefaultArg = 9; // expected-note {{'DefaultArg' declared here}}
109 template <int I = defaultArg> struct S {}; // expected-error {{use of undeclared identifier 'defaultArg'; did you mean 'DefaultArg'?}}
110 S<1> s;
112 namespace foo {}
113 void test_paren_suffix() {
114 foo::bar({5, 6}); // expected-error-re {{no member named 'bar' in namespace 'foo'{{$}}}}
115 #if __cplusplus <= 199711L
116 // expected-error@-2 {{expected expression}}
117 #endif
120 const int kNum = 10; // expected-note {{'kNum' declared here}}
121 class SomeClass {
122 int Kind;
123 public:
124 explicit SomeClass() : Kind(kSum) {} // expected-error {{use of undeclared identifier 'kSum'; did you mean 'kNum'?}}
127 // There used to be an issue with typo resolution inside overloads.
128 struct AssertionResult { ~AssertionResult(); };
129 AssertionResult Overload(const char *a);
130 AssertionResult Overload(int a);
131 void UseOverload() {
132 // expected-note@+1 {{'result' declared here}}
133 const char *result;
134 // expected-error@+1 {{use of undeclared identifier 'resulta'; did you mean 'result'?}}
135 Overload(resulta);
138 namespace PR21925 {
139 struct X {
140 int get() { return 7; } // expected-note {{'get' declared here}}
142 void test() {
143 X variable; // expected-note {{'variable' declared here}}
145 // expected-error@+2 {{use of undeclared identifier 'variableX'; did you mean 'variable'?}}
146 // expected-error@+1 {{no member named 'getX' in 'PR21925::X'; did you mean 'get'?}}
147 int x = variableX.getX();
151 namespace PR21905 {
152 int (*a)() = (void)Z; // expected-error-re {{use of undeclared identifier 'Z'{{$}}}} \
153 // expected-error {{cannot initialize a variable of type 'int (*)()' with an rvalue of type 'void'}}
156 namespace PR21947 {
157 int blue; // expected-note {{'blue' declared here}}
158 __typeof blur y; // expected-error {{use of undeclared identifier 'blur'; did you mean 'blue'?}}
161 namespace PR22092 {
162 a = b ? : 0; // expected-error {{a type specifier is required for all declarations}} \
163 // expected-error-re {{use of undeclared identifier 'b'{{$}}}}
166 extern long clock (void);
167 struct Pointer {
168 void set_xpos(int);
169 void set_ypos(int);
171 void MovePointer(Pointer &Click, int x, int y) { // expected-note 2 {{'Click' declared here}}
172 click.set_xpos(x); // expected-error {{use of undeclared identifier 'click'; did you mean 'Click'?}}
173 click.set_ypos(x); // expected-error {{use of undeclared identifier 'click'; did you mean 'Click'?}}
176 namespace PR22250 {
177 // expected-error@+4 {{use of undeclared identifier 'size_t'; did you mean 'sizeof'?}}
178 // expected-error-re@+3 {{use of undeclared identifier 'y'{{$}}}}
179 // expected-error-re@+2 {{use of undeclared identifier 'z'{{$}}}}
180 // expected-error@+1 {{expected ';' after top level declarator}}
181 int getenv_s(size_t *y, char(&z)) {}
184 namespace PR22291 {
185 template <unsigned I> void f() {
186 unsigned *prio_bits_array; // expected-note {{'prio_bits_array' declared here}}
187 // expected-error@+1 {{use of undeclared identifier 'prio_op_array'; did you mean 'prio_bits_array'?}}
188 __atomic_store_n(prio_op_array + I, false, __ATOMIC_RELAXED);
192 namespace PR22297 {
193 double pow(double x, double y);
194 struct TimeTicks {
195 static void Now(); // expected-note {{'Now' declared here}}
197 void f() {
198 TimeTicks::now(); // expected-error {{no member named 'now' in 'PR22297::TimeTicks'; did you mean 'Now'?}}
202 namespace PR23005 {
203 void f() { int a = Unknown::b(c); } // expected-error {{use of undeclared identifier 'Unknown'}}
204 // expected-error@-1 {{use of undeclared identifier 'c'}}
207 namespace PR23350 {
208 int z = 1 ? N : ; // expected-error {{expected expression}}
209 // expected-error-re@-1 {{use of undeclared identifier 'N'{{$}}}}
212 // PR 23285. This test must be at the end of the file to avoid additional,
213 // unwanted diagnostics.
214 // expected-error-re@+2 {{use of undeclared identifier 'uintmax_t'{{$}}}}
215 // expected-error@+1 {{expected ';' after top level declarator}}
216 unsigned int a = 0(uintmax_t