xref: /llvm-project/clang/test/SemaCXX/typo-correction.cpp (revision 8282c58d9b1cd5b6df89ee3f68438fe0ee672f7f)
1 // RUN: %clang_cc1 -fspell-checking-limit=0 -verify -Wno-c++11-extensions -fcxx-exceptions %s
2 // RUN: %clang_cc1 -fspell-checking-limit=0 -verify -Wno-c++11-extensions -fcxx-exceptions -std=c++20 %s
3 
4 namespace PR21817{
5 int a(-rsing[2]); // expected-error {{undeclared identifier 'rsing'; did you mean 'using'?}}
6                   // expected-error@-1 {{expected expression}}
7 }
8 
9 struct errc {
10   int v_;
11   operator int() const {return v_;}
12 };
13 
14 class error_condition
15 {
16   int _val_;
17 public:
18   error_condition() : _val_(0) {}
19 
20   error_condition(int _val)
21     : _val_(_val) {}
22 
23   template <class E>
24   error_condition(E _e) {
25     // make_error_condition must not be typo corrected to error_condition
26     // even though the first declaration of make_error_condition has not
27     // yet been encountered. This was a bug in the first version of the type
28     // name typo correction patch that wasn't noticed until building LLVM with
29     // Clang failed.
30     *this = make_error_condition(_e);
31   }
32 
33 };
34 
35 inline error_condition make_error_condition(errc _e) {
36   return error_condition(static_cast<int>(_e));
37 }
38 
39 
40 // Prior to the introduction of a callback object to further filter possible
41 // typo corrections, this example would not trigger a suggestion as "base_type"
42 // is a closer match to "basetype" than is "BaseType" but "base_type" does not
43 // refer to a base class or non-static data member.
44 struct BaseType { };
45 struct Derived : public BaseType { // expected-note {{base class 'BaseType' specified here}}
46   static int base_type; // expected-note {{'base_type' declared here}}
47   Derived() : basetype() {} // expected-error{{initializer 'basetype' does not name a non-static data member or base class; did you mean the base class 'BaseType'?}}
48 };
49 
50 // Test the improvement from passing a callback object to CorrectTypo in
51 // the helper function LookupMemberExprInRecord.
52 int get_type(struct Derived *st) {
53   return st->Base_Type; // expected-error{{no member named 'Base_Type' in 'Derived'; did you mean 'base_type'?}}
54 }
55 
56 // In this example, somename should not be corrected to the cached correction
57 // "some_name" since "some_name" is a class and a namespace name is needed.
58 class some_name {}; // expected-note {{'some_name' declared here}}
59 somename Foo; // expected-error {{unknown type name 'somename'; did you mean 'some_name'?}}
60 namespace SomeName {} // expected-note {{namespace 'SomeName' defined here}}
61 using namespace somename; // expected-error {{no namespace named 'somename'; did you mean 'SomeName'?}}
62 
63 
64 // Without the callback object, CorrectTypo would choose "field1" as the
65 // correction for "fielda" as it is closer than "FieldA", but that correction
66 // would be later discarded by the caller and no suggestion would be given.
67 struct st {
68   struct {
69     int field1;
70   };
71   double FieldA; // expected-note{{'FieldA' declared here}}
72 };
73 st var = { .fielda = 0.0 }; // expected-error{{field designator 'fielda' does not refer to any field in type 'st'; did you mean 'FieldA'?}}
74 
75 // Test the improvement from passing a callback object to CorrectTypo in
76 // Sema::BuildCXXNestedNameSpecifier. And also for the improvement by doing
77 // so in Sema::getTypeName.
78 typedef char* another_str; // expected-note{{'another_str' declared here}}
79 namespace AnotherStd { // expected-note{{'AnotherStd' declared here}}
80   class string {};
81 }
82 another_std::string str; // expected-error{{use of undeclared identifier 'another_std'; did you mean 'AnotherStd'?}}
83 another_str *cstr = new AnotherStr; // expected-error{{unknown type name 'AnotherStr'; did you mean 'another_str'?}}
84 
85 // Test the improvement from passing a callback object to CorrectTypo in
86 // Sema::ActOnSizeofParameterPackExpr.
87 char* TireNames;
88 template<typename ...TypeNames> struct count { // expected-note{{parameter pack 'TypeNames' declared here}}
89   static const unsigned value = sizeof...(TyreNames); // expected-error{{'TyreNames' does not refer to the name of a parameter pack; did you mean 'TypeNames'?}}
90 };
91 
92 // Test the typo-correction callback in Sema::DiagnoseUnknownTypeName.
93 namespace unknown_type_test {
94   class StreamOut {}; // expected-note 2 {{'StreamOut' declared here}}
95   long stream_count; // expected-note 2 {{'stream_count' declared here}}
96 };
97 unknown_type_test::stream_out out; // expected-error{{no type named 'stream_out' in namespace 'unknown_type_test'; did you mean 'StreamOut'?}}
98 
99 // Demonstrate a case where using only the cached value returns the wrong thing
100 // when the cached value was the result of a previous callback object that only
101 // accepts a subset of the current callback object.
102 namespace cache_invalidation_test {
103 using namespace unknown_type_test;
104 void bar(long i);
105 void before_caching_classname() {
106   bar((stream_out)); // expected-error{{use of undeclared identifier 'stream_out'; did you mean 'stream_count'?}}
107 }
108 stream_out out; // expected-error{{unknown type name 'stream_out'; did you mean 'StreamOut'?}}
109 void after_caching_classname() {
110   bar((stream_out)); // expected-error{{use of undeclared identifier 'stream_out'; did you mean 'stream_count'?}}
111 }
112 }
113 
114 // Test the typo-correction callback in Sema::DiagnoseInvalidRedeclaration.
115 struct BaseDecl {
116   void add_in(int i);
117 };
118 struct TestRedecl : public BaseDecl {
119   void add_it(int i); // expected-note{{'add_it' declared here}}
120 };
121 void TestRedecl::add_in(int i) {} // expected-error{{out-of-line definition of 'add_in' does not match any declaration in 'TestRedecl'; did you mean 'add_it'?}}
122 
123 // Test the improved typo correction for the Parser::ParseCastExpr =>
124 // Sema::ActOnIdExpression => Sema::DiagnoseEmptyLookup call path.
125 class SomeNetMessage; // expected-note 2{{'SomeNetMessage'}}
126 class Message {};
127 void foo(Message&);
128 void foo(SomeNetMessage&);
129 void doit(void *data) {
130   Message somenetmsg; // expected-note{{'somenetmsg' declared here}}
131   foo(somenetmessage); // expected-error{{use of undeclared identifier 'somenetmessage'; did you mean 'somenetmsg'?}}
132   foo((somenetmessage)data); // expected-error{{unknown type name 'somenetmessage'; did you mean 'SomeNetMessage'?}} expected-error{{incomplete type}}
133 }
134 
135 // Test the typo-correction callback in BuildRecoveryCallExpr.
136 // Solves the main issue in PR 9320 of suggesting corrections that take the
137 // wrong number of arguments.
138 void revoke(const char*); // expected-note 2{{'revoke' declared here}}
139 void Test() {
140   Invoke(); // expected-error{{use of undeclared identifier 'Invoke'}}
141   Invoke("foo"); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'revoke'?}}
142   Invoke("foo", "bar"); // expected-error{{use of undeclared identifier 'Invoke'}}
143 }
144 void Test2(void (*invoke)(const char *, int)) { // expected-note{{'invoke' declared here}}
145   Invoke(); // expected-error{{use of undeclared identifier 'Invoke'}}
146   Invoke("foo"); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'revoke'?}}
147   Invoke("foo", 7); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'invoke'?}}
148   Invoke("foo", 7, 22); // expected-error{{use of undeclared identifier 'Invoke'}}
149 }
150 
151 void provoke(const char *x, bool y=false) {} // expected-note 2{{'provoke' declared here}}
152 void Test3() {
153   Provoke(); // expected-error{{use of undeclared identifier 'Provoke'}}
154   Provoke("foo"); // expected-error{{use of undeclared identifier 'Provoke'; did you mean 'provoke'?}}
155   Provoke("foo", true); // expected-error{{use of undeclared identifier 'Provoke'; did you mean 'provoke'?}}
156   Provoke("foo", 7, 22); // expected-error{{use of undeclared identifier 'Provoke'}}
157 }
158 
159 // PR 11737 - Don't try to typo-correct the implicit 'begin' and 'end' in a
160 // C++11 for-range statement.
161 struct R {};
162 bool begun(R);
163 void RangeTest() {
164   for (auto b : R()) {} // expected-error {{invalid range expression of type 'R'}}
165 }
166 
167 // PR 12019 - Avoid infinite mutual recursion in DiagnoseInvalidRedeclaration
168 // by not trying to typo-correct a method redeclaration to declarations not
169 // in the current record.
170 class Parent {
171  void set_types(int index, int value);
172  void add_types(int value);
173 };
174 class Child: public Parent {};
175 void Child::add_types(int value) {} // expected-error{{out-of-line definition of 'add_types' does not match any declaration in 'Child'}}
176                                     // expected-note@-2{{defined here}}
177 
178 // Fix the callback based filtering of typo corrections within
179 // Sema::ActOnIdExpression by Parser::ParseCastExpression to allow type names as
180 // potential corrections for template arguments.
181 namespace clash {
182 class ConstructExpr {}; // expected-note 2{{'clash::ConstructExpr' declared here}}
183 }
184 class ClashTool {
185   bool HaveConstructExpr();
186   template <class T> T* getExprAs();
187 
188   void test() {
189     ConstructExpr *expr = // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}}
190         getExprAs<ConstructExpr>(); // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}}
191   }
192 };
193 
194 namespace test1 {
195   struct S {
196     struct Foobar *f;  // expected-note{{'Foobar' declared here}}
197   };
198   test1::FooBar *b;  // expected-error{{no type named 'FooBar' in namespace 'test1'; did you mean 'Foobar'?}}
199 }
200 
201 namespace ImplicitInt {
202   void f(int, unsinged); // expected-error{{did you mean 'unsigned'}}
203   struct S {
204     unsinged : 4; // expected-error{{did you mean 'unsigned'}}
205   };
206 }
207 
208 namespace PR13051 {
209   template<typename T> struct S {
210     template<typename U> void f();
211     operator bool() const;
212   };
213 
214   void foo(); // expected-note{{'foo' declared here}}
215   void g(void(*)()); // expected-note{{candidate function not viable}}
216   void g(bool(S<int>::*)() const); // expected-note{{candidate function not viable}}
217 
218   void test() {
219     g(&S<int>::tempalte f<int>); // expected-error{{did you mean 'template'?}} \
220                                  // expected-error{{no matching function for call to 'g'}}
221     g(&S<int>::opeartor bool); // expected-error{{did you mean 'operator'?}}
222     g(&S<int>::foo); // expected-error{{no member named 'foo' in 'PR13051::S<int>'; did you mean simply 'foo'?}}
223   }
224 }
225 
226 inf f(doulbe); // expected-error{{'int'}} expected-error{{'double'}}
227 
228 namespace PR6325 {
229 class foo { }; // expected-note{{'foo' declared here}}
230 // Note that for this example (pulled from the PR), if keywords are not excluded
231 // as correction candidates then no suggestion would be given; correcting
232 // 'boo' to 'bool' is the same edit distance as correcting 'boo' to 'foo'.
233 class bar : boo { }; // expected-error{{unknown class name 'boo'; did you mean 'foo'?}}
234 }
235 
236 namespace outer {
237   void somefunc();  // expected-note{{'::outer::somefunc' declared here}}
238   void somefunc(int, int);  // expected-note{{'::outer::somefunc' declared here}}
239 
240   namespace inner {
241     void somefunc(int) {
242       someFunc();  // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}}
243       someFunc(1, 2);  // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}}
244     }
245   }
246 }
247 
248 namespace b6956809_test1 {
249   struct A {};
250   struct B {};
251 
252   struct S1 {
253     void method(A*);  // no note here
254     void method(B*);  // expected-note{{'method' declared here}}
255   };
256 
257   void test1() {
258     B b;
259     S1 s;
260     s.methodd(&b);  // expected-error{{no member named 'methodd' in 'b6956809_test1::S1'; did you mean 'method'}}
261   }
262 
263   struct S2 {
264     S2();
265     void method(A*) const;
266    private:
267     void method(B*);
268   };
269 
270   void test2() {
271     B b;
272     const S2 s;
273     s.methodd(&b);  // expected-error-re{{no member named 'methodd' in 'b6956809_test1::S2'{{$}}}}
274   }
275 }
276 
277 namespace b6956809_test2 {
278   template<typename T> struct Err { typename T::error n; };  // expected-error{{type 'void *' cannot be used prior to '::' because it has no members}}
279   struct S {
280     template<typename T> typename Err<T>::type method(T);  // expected-note{{in instantiation of template class 'b6956809_test2::Err<void *>' requested here}}
281     template<typename T> int method(T *);  // expected-note{{'method' declared here}}
282   };
283 
284   void test() {
285     S s;
286     int k = s.methodd((void*)0);  // expected-error{{no member named 'methodd' in 'b6956809_test2::S'; did you mean 'method'?}} expected-note{{while substituting deduced template arguments into function template 'method' [with T = void *]}}
287   }
288 }
289 
290 namespace PR12951 {
291 // If there are two corrections that have the same identifier and edit distance
292 // and only differ by their namespaces, don't suggest either as a correction
293 // since both are equally likely corrections.
294 namespace foobar { struct Thing {}; }
295 namespace bazquux { struct Thing {}; }
296 void f() { Thing t; } // expected-error{{unknown type name 'Thing'}}
297 }
298 
299 namespace bogus_keyword_suggestion {
300 void test() {
301    status = "OK";  // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
302    return status;  // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
303  }
304 }
305 
306 namespace PR13387 {
307 struct A {
308   void CreateFoo(float, float);
309   void CreateBar(float, float);
310 };
311 struct B : A {
312   using A::CreateFoo; // expected-note {{'CreateFoo' declared here}}
313   void CreateFoo(int, int);  // expected-note {{'CreateFoo' declared here}}
314 };
315 void f(B &x) {
316   x.Createfoo(0,0);  // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}
317   x.Createfoo(0.f,0.f);  // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}
318 }
319 }
320 
321 namespace using_decl {
322   namespace somewhere { int foobar; }
323   using somewhere::foobar; // expected-note {{declared here}}
324   int k = goobar; // expected-error {{did you mean 'foobar'?}}
325 }
326 
327 struct DataStruct {void foo();};
328 struct T {
329  DataStruct data_struct;
330  void f();
331 };
332 // should be void T::f();
333 void f() {
334  data_struct->foo();  // expected-error-re{{use of undeclared identifier 'data_struct'{{$}}}}
335 }
336 
337 namespace PR12287 {
338 class zif {
339   void nab(int);
340 };
341 void nab();  // expected-note{{'::PR12287::nab' declared here}}
342 void zif::nab(int) {
343   nab();  // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::PR12287::nab'?}}
344 }
345 }
346 
347 namespace TemplateFunction {
348 template <class T>
349 void fnA(T) { }  // expected-note {{'::TemplateFunction::fnA' declared here}}
350 
351 template <class T>
352 void fnB(T) { }  // expected-note {{'::TemplateFunction::fnB' declared here}}
353 
354 class Foo {
355  public:
356   void fnA(int, int) {}
357   void fnB() {}
358 };
359 
360 void test(Foo F, int num) {
361   F.fnA(num);  // expected-error {{too few arguments to function call, expected 2, have 1; did you mean '::TemplateFunction::fnA'?}}
362   F.fnB(num);  // expected-error {{too many arguments to function call, expected 0, have 1; did you mean '::TemplateFunction::fnB'?}}
363 }
364 }
365 namespace using_suggestion_val_dropped_specifier {
366 void FFF() {} // expected-note {{'::using_suggestion_val_dropped_specifier::FFF' declared here}}
367 namespace N { }
368 using N::FFF; // expected-error {{no member named 'FFF' in namespace 'using_suggestion_val_dropped_specifier::N'; did you mean '::using_suggestion_val_dropped_specifier::FFF'?}}
369 }
370 
371 namespace class_member_typo_corrections {
372 class Outer {
373 public:
374   class Inner {};  // expected-note {{'Outer::Inner' declared here}}
375   Inner MyMethod(Inner arg);
376 };
377 
378 Inner Outer::MyMethod(Inner arg) {  // expected-error {{unknown type name 'Inner'; did you mean 'Outer::Inner'?}}
379   return Inner();
380 }
381 
382 class Result {
383 public:
384   enum ResultType {
385     ENTITY,  // expected-note {{'Result::ENTITY' declared here}}
386     PREDICATE,  // expected-note {{'Result::PREDICATE' declared here}}
387     LITERAL  // expected-note {{'Result::LITERAL' declared here}}
388   };
389 
390   ResultType type();
391 };
392 
393 void test() {
394   Result result_cell;
395   switch (result_cell.type()) {
396   case ENTITY:  // expected-error {{use of undeclared identifier 'ENTITY'; did you mean 'Result::ENTITY'?}}
397   case LITERAL:  // expected-error {{use of undeclared identifier 'LITERAL'; did you mean 'Result::LITERAL'?}}
398   case PREDICAT:  // expected-error {{use of undeclared identifier 'PREDICAT'; did you mean 'Result::PREDICATE'?}}
399     break;
400   }
401 }
402 
403 class Figure {
404   enum ResultType {
405     SQUARE,
406     TRIANGLE,
407     CIRCLE
408   };
409 
410 public:
411   ResultType type();
412 };
413 
414 void testAccess() {
415   Figure obj;
416   switch (obj.type()) {
417   case SQUARE:  // expected-error-re {{use of undeclared identifier 'SQUARE'{{$}}}}
418   case TRIANGLE:  // expected-error-re {{use of undeclared identifier 'TRIANGLE'{{$}}}}
419   case CIRCE:  // expected-error-re {{use of undeclared identifier 'CIRCE'{{$}}}}
420     break;
421   }
422 }
423 }
424 
425 long readline(const char *, char *, unsigned long);
426 void assign_to_unknown_var() {
427     deadline_ = 1;  // expected-error-re {{use of undeclared identifier 'deadline_'{{$}}}}
428 }
429 
430 namespace no_ns_before_dot {
431 namespace re2 {}
432 void test() {
433     req.set_check(false);  // expected-error-re {{use of undeclared identifier 'req'{{$}}}}
434 }
435 }
436 
437 namespace PR17394 {
438   class A {
439   protected:
440     long zzzzzzzzzz;
441   };
442   class B : private A {};
443   B zzzzzzzzzy<>; // expected-error {{template specialization requires 'template<>'}} expected-error {{no variable template matches specialization}}
444 }
445 
446 namespace correct_fields_in_member_funcs {
447 struct S {
448   int my_member;  // expected-note {{'my_member' declared here}}
449   void f() { my_menber = 1; }  // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}}
450 };
451 }
452 
453 namespace PR17019 {
454   template<class F>
455   struct evil {
456     evil(F de) {  // expected-note {{'de' declared here}}
457       de_;  // expected-error {{use of undeclared identifier 'de_'; did you mean 'de'?}} \
458             // expected-warning {{expression result unused}}
459     }
460     ~evil() {
461       de_->bar()  // expected-error {{use of undeclared identifier 'de_'}}
462     }
463   };
464 
465   void meow() {
466     evil<int> Q(0); // expected-note {{in instantiation of member function}}
467   }
468 }
469 
470 namespace fix_class_name_qualifier {
471 class MessageHeaders {};
472 class MessageUtils {
473  public:
474   static void ParseMessageHeaders(int, int); // expected-note {{'MessageUtils::ParseMessageHeaders' declared here}}
475 };
476 
477 void test() {
478   // No, we didn't mean to call MessageHeaders::MessageHeaders.
479   MessageHeaders::ParseMessageHeaders(5, 4); // expected-error {{no member named 'ParseMessageHeaders' in 'fix_class_name_qualifier::MessageHeaders'; did you mean 'MessageUtils::ParseMessageHeaders'?}}
480 }
481 }
482 
483 namespace PR18213 {  // expected-note {{'PR18213' declared here}}
484 struct WrapperInfo {
485   int i;
486 };
487 
488 template <typename T> struct Wrappable {
489   static WrapperInfo kWrapperInfo;
490 };
491 
492 // Note the space before "::PR18213" is intended and needed, as it highlights
493 // the actual typo, which is the leading "::".
494 // TODO: Suggest removing the "::" from "::PR18213" (the right correction)
495 // instead of incorrectly suggesting dropping "PR18213::WrapperInfo::".
496 template <>
497 PR18213::WrapperInfo ::PR18213::Wrappable<int>::kWrapperInfo = { 0 };  // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \
498                                                                        // expected-error {{a type specifier is required for all declarations}}
499 }
500 
501 namespace PR18651 {
502 struct {
503   int x;
504 } a, b;
505 
506 int y = x;  // expected-error-re {{use of undeclared identifier 'x'{{$}}}}
507 }
508 
509 namespace PR18685 {
510 template <class C, int I, int J>
511 class SetVector {
512  public:
513   SetVector() {}
514 };
515 
516 template <class C, int I>
517 class SmallSetVector : public SetVector<C, I, 8> {};
518 
519 class foo {};
520 SmallSetVector<foo*, 2> fooSet;
521 }
522 
523 PR18685::BitVector Map;  // expected-error-re {{no type named 'BitVector' in namespace 'PR18685'{{$}}}}
524 
525 namespace shadowed_template {
526 template <typename T> class Fizbin {};  // expected-note {{'::shadowed_template::Fizbin' declared here}}
527 class Baz {
528    int Fizbin;
529    Fizbin<int> qux; // expected-error {{no template named 'Fizbin'; did you mean '::shadowed_template::Fizbin'?}}
530 };
531 }
532 
533 namespace no_correct_template_id_to_non_template {
534   struct Frobnatz {}; // expected-note {{declared here}}
535   Frobnats fn; // expected-error {{unknown type name 'Frobnats'; did you mean 'Frobnatz'?}}
536   Frobnats<int> fni; // expected-error-re {{no template named 'Frobnats'{{$}}}}
537 }
538 
539 namespace PR18852 {
540 void func() {
541   struct foo {
542     void barberry() {}
543   };
544   barberry();  // expected-error-re {{use of undeclared identifier 'barberry'{{$}}}}
545 }
546 
547 class Thread {
548  public:
549   void Start();
550   static void Stop();  // expected-note {{'Thread::Stop' declared here}}
551 };
552 
553 class Manager {
554  public:
555   void Start(int);  // expected-note {{'Start' declared here}}
556   void Stop(int);  // expected-note {{'Stop' declared here}}
557 };
558 
559 void test(Manager *m) {
560   // Don't suggest Thread::Start as a correction just because it has the same
561   // (unqualified) name and accepts the right number of args; this is a method
562   // call on an object in an unrelated class.
563   m->Start();  // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
564   m->Stop();  // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
565   Stop();  // expected-error {{use of undeclared identifier 'Stop'; did you mean 'Thread::Stop'?}}
566 }
567 
568 }
569 
570 namespace std {
571 class bernoulli_distribution {
572  public:
573   double p() const;
574 };
575 }
576 void test() {
577   // Make sure that typo correction doesn't suggest changing 'p' to
578   // 'std::bernoulli_distribution::p' as that is most likely wrong.
579   if (p)  // expected-error-re {{use of undeclared identifier 'p'{{$}}}}
580     return;
581 }
582 
583 namespace PR19681 {
584   struct TypoA {};
585   struct TypoB {
586     void test();
587   private:
588     template<typename T> void private_memfn(T);  // expected-note{{declared here}}
589   };
590   void TypoB::test() {
591     // FIXME: should suggest 'PR19681::TypoB::private_memfn' instead of '::PR19681::TypoB::private_memfn'
592     (void)static_cast<void(TypoB::*)(int)>(&TypoA::private_memfn);  // expected-error{{no member named 'private_memfn' in 'PR19681::TypoA'; did you mean '::PR19681::TypoB::private_memfn'?}}
593   }
594 }
595 
596 namespace testWantFunctionLikeCasts {
597   long test(bool a) {
598     if (a)
599       return struc(5.7);  // expected-error-re {{use of undeclared identifier 'struc'{{$}}}}
600     else
601       return lon(8.0);  // expected-error {{use of undeclared identifier 'lon'; did you mean 'long'?}}
602   }
603 }
604 
605 namespace testCXXDeclarationSpecifierParsing {
606 namespace test {
607   struct SomeSettings {};  // expected-note {{'test::SomeSettings' declared here}}
608 }
609 class Test {};
610 int bar() {
611   Test::SomeSettings some_settings; // expected-error {{no type named 'SomeSettings' in 'testCXXDeclarationSpecifierParsing::Test'; did you mean 'test::SomeSettings'?}}
612 }
613 }
614 
615 namespace testIncludeTypeInTemplateArgument {
616 template <typename T, typename U>
617 void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
618 
619 class AddObservation {}; // expected-note {{declared here}}
620 int bar1() {
621   // should resolve to a class.
622   foo<AddObservationFn, int>(); // expected-error {{unknown type name 'AddObservationFn'; did you mean 'AddObservation'?}}
623 
624   // should not resolve to a class.
625   foo(AddObservationFn, 1);    // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$}}}}
626   int a = AddObservationFn, b; // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$}}}}
627 
628   int AddObservation; // expected-note 3{{declared here}}
629   // should resolve to a local variable.
630   foo(AddObservationFn, 1);    // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
631   int c = AddObservationFn, d; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
632 
633   // FIXME: would be nice to not resolve to a variable.
634   foo<AddObservationFn, int>(); // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} \
635                                    expected-error {{no matching function for call}}
636 }
637 } // namespace testIncludeTypeInTemplateArgument
638 
639 namespace testNoCrashOnNullNNSTypoCorrection {
640 int AddObservation();
641 template <typename T, typename... Args>
642 class UsingImpl {};
643 class AddObservation { // expected-note {{declared here}}
644   using Using =
645       // should resolve to a class.
646       UsingImpl<AddObservationFn, const int>; // expected-error {{unknown type name 'AddObservationFn'; did you mean}}
647 };
648 } // namespace testNoCrashOnNullNNSTypoCorrection
649 
650 namespace testNonStaticMemberHandling {
651 struct Foo {
652   bool usesMetadata;  // expected-note {{'usesMetadata' declared here}}
653 };
654 int test(Foo f) {
655   if (UsesMetadata)  // expected-error-re {{use of undeclared identifier 'UsesMetadata'{{$}}}}
656     return 5;
657   if (f.UsesMetadata)  // expected-error {{no member named 'UsesMetadata' in 'testNonStaticMemberHandling::Foo'; did you mean 'usesMetadata'?}}
658     return 11;
659   return 0;
660 }
661 };
662 
663 namespace testMemberExprDeclarationNameInfo {
664   // The AST should only have the corrected name with no mention of 'data_'.
665   void f(int);
666   struct S {
667     int data;  // expected-note 2{{'data' declared here}}
668     void m_fn1() {
669       data_  // expected-error {{use of undeclared identifier 'data_'}}
670           [] =  // expected-error {{expected expression}}
671           f(data_);  // expected-error {{use of undeclared identifier 'data_'}}
672     }
673   };
674 }
675 
676 namespace testArraySubscriptIndex {
677   struct S {
678     int data;  // expected-note {{'data' declared here}}
679     void m_fn1() {
680       (+)[data_];  // expected-error{{expected expression}} expected-error {{use of undeclared identifier 'data_'; did you mean 'data'}}
681     }
682   };
683 }
684 
685 namespace crash_has_include {
686 int has_include(int); // expected-note {{'has_include' declared here}}
687 // expected-error@+1 {{'__has_include' must be used within a preprocessing directive}}
688 int foo = __has_include(42); // expected-error {{use of undeclared identifier '__has_include'; did you mean 'has_include'?}}
689 }
690 
691 namespace PR24781_using_crash {
692 namespace A {
693 namespace B {
694 class Foofoo {};  // expected-note {{'A::B::Foofoo' declared here}}
695 }
696 }
697 
698 namespace C {
699 namespace D {
700 class Bar : public A::B::Foofoo {};
701 }
702 }
703 
704 using C::D::Foofoo;  // expected-error {{no member named 'Foofoo' in namespace 'PR24781_using_crash::C::D'; did you mean 'A::B::Foofoo'?}}
705 }
706 
707 int d = ? L : d; // expected-error {{expected expression}} expected-error {{undeclared identifier}}
708 
709 struct B0 {
710   int : 0 |         // expected-error {{invalid operands to binary expression}}
711       (struct B0)e; // expected-error {{use of undeclared identifier}}
712 };
713 
714 namespace {
715 struct a0is0 {};
716 struct b0is0 {};
717 int g() {
718   0 [
719       sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
720 };
721 }
722 
723 namespace avoidRedundantRedefinitionErrors {
724 class Class {
725   void function(int pid); // expected-note {{'function' declared here}}
726 };
727 
728 void Class::function2(int pid) { // expected-error {{out-of-line definition of 'function2' does not match any declaration in 'avoidRedundantRedefinitionErrors::Class'; did you mean 'function'?}}
729 }
730 
731 // Expected no redefinition error here.
732 void Class::function(int pid) { // expected-note {{previous definition is here}}
733 }
734 
735 void Class::function(int pid) { // expected-error {{redefinition of 'function'}}
736 }
737 
738 namespace ns {
739 void create_test(); // expected-note {{'create_test' declared here}}
740 }
741 
742 void ns::create_test2() { // expected-error {{out-of-line definition of 'create_test2' does not match any declaration in namespace 'avoidRedundantRedefinitionErrors::ns'; did you mean 'create_test'?}}
743 }
744 
745 // Expected no redefinition error here.
746 void ns::create_test() {
747 }
748 }
749 
750 namespace PR46487 {
751   bool g_var_bool; // expected-note {{here}}
752   const char g_volatile_char = 5; // expected-note {{here}}
753   // FIXME: We shouldn't suggest a typo-correction to 'g_var_bool' here,
754   // because it doesn't make the expression valid.
755   // expected-error@+2 {{did you mean 'g_var_bool'}}
756   // expected-error@+1 {{assigning to 'bool' from incompatible type 'void'}}
757   enum : typename decltype((g_var_long = throw))::a {
758     b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
759   };
760 }
761 
762 namespace PR47272
763 {
764 
765 namespace Views {
766 int Take(); // expected-note{{'Views::Take' declared here}}
767 }
768 
769 namespace [[deprecated("use Views instead")]] View {
770 using Views::Take;
771 }
772 
773 namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked deprecated here}}
774 int pr47272;
775 }
776 
777 namespace B {
778 using A::pr47272;  // expected-note{{'B::pr47272' declared here}} expected-warning{{'A' is deprecated}}
779 }
780 
781 namespace [[deprecated]] C {
782 using A::pr47272;
783 }
784 
785 void function() {
786   int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}}
787   int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}}
788 }
789 }
790 
791 
792