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_;
operator interrc11   operator int() const {return v_;}
12 };
13 
14 class error_condition
15 {
16   int _val_;
17 public:
error_condition()18   error_condition() : _val_(0) {}
19 
error_condition(int _val)20   error_condition(int _val)
21     : _val_(_val) {}
22 
23   template <class E>
error_condition(E _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 
make_error_condition(errc _e)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}}
DerivedDerived47   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.
get_type(struct Derived * st)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);
before_caching_classname()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'?}}
after_caching_classname()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 };
add_in(int i)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&);
doit(void * data)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}}
Test()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 }
Test2(void (* invoke)(const char *,int))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 
provoke(const char * x,bool y=false)151 void provoke(const char *x, bool y=false) {} // expected-note 2{{'provoke' declared here}}
Test3()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);
RangeTest()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 {};
add_types(int value)175 void Child::add_types(int value) {} // expected-error{{out-of-line definition of 'add_types' does not match any declaration in 'Child'}}
176 
177 // Fix the callback based filtering of typo corrections within
178 // Sema::ActOnIdExpression by Parser::ParseCastExpression to allow type names as
179 // potential corrections for template arguments.
180 namespace clash {
181 class ConstructExpr {}; // expected-note 2{{'clash::ConstructExpr' declared here}}
182 }
183 class ClashTool {
184   bool HaveConstructExpr();
185   template <class T> T* getExprAs();
186 
test()187   void test() {
188     ConstructExpr *expr = // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}}
189         getExprAs<ConstructExpr>(); // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}}
190   }
191 };
192 
193 namespace test1 {
194   struct S {
195     struct Foobar *f;  // expected-note{{'Foobar' declared here}}
196   };
197   test1::FooBar *b;  // expected-error{{no type named 'FooBar' in namespace 'test1'; did you mean 'Foobar'?}}
198 }
199 
200 namespace ImplicitInt {
201   void f(int, unsinged); // expected-error{{did you mean 'unsigned'}}
202   struct S {
203     unsinged : 4; // expected-error{{did you mean 'unsigned'}}
204   };
205 }
206 
207 namespace PR13051 {
208   template<typename T> struct S {
209     template<typename U> void f();
210     operator bool() const;
211   };
212 
213   void foo(); // expected-note{{'foo' declared here}}
214   void g(void(*)()); // expected-note{{candidate function not viable}}
215   void g(bool(S<int>::*)() const); // expected-note{{candidate function not viable}}
216 
test()217   void test() {
218     g(&S<int>::tempalte f<int>); // expected-error{{did you mean 'template'?}} \
219                                  // expected-error{{no matching function for call to 'g'}}
220     g(&S<int>::opeartor bool); // expected-error{{did you mean 'operator'?}}
221     g(&S<int>::foo); // expected-error{{no member named 'foo' in 'PR13051::S<int>'; did you mean simply 'foo'?}}
222   }
223 }
224 
225 inf f(doulbe); // expected-error{{'int'}} expected-error{{'double'}}
226 
227 namespace PR6325 {
228 class foo { }; // expected-note{{'foo' declared here}}
229 // Note that for this example (pulled from the PR), if keywords are not excluded
230 // as correction candidates then no suggestion would be given; correcting
231 // 'boo' to 'bool' is the same edit distance as correcting 'boo' to 'foo'.
232 class bar : boo { }; // expected-error{{unknown class name 'boo'; did you mean 'foo'?}}
233 }
234 
235 namespace outer {
236   void somefunc();  // expected-note{{'::outer::somefunc' declared here}}
237   void somefunc(int, int);  // expected-note{{'::outer::somefunc' declared here}}
238 
239   namespace inner {
somefunc(int)240     void somefunc(int) {
241       someFunc();  // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}}
242       someFunc(1, 2);  // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}}
243     }
244   }
245 }
246 
247 namespace b6956809_test1 {
248   struct A {};
249   struct B {};
250 
251   struct S1 {
252     void method(A*);  // no note here
253     void method(B*);  // expected-note{{'method' declared here}}
254   };
255 
test1()256   void test1() {
257     B b;
258     S1 s;
259     s.methodd(&b);  // expected-error{{no member named 'methodd' in 'b6956809_test1::S1'; did you mean 'method'}}
260   }
261 
262   struct S2 {
263     S2();
264     void method(A*) const;
265    private:
266     void method(B*);
267   };
268 
test2()269   void test2() {
270     B b;
271     const S2 s;
272     s.methodd(&b);  // expected-error-re{{no member named 'methodd' in 'b6956809_test1::S2'{{$}}}}
273   }
274 }
275 
276 namespace b6956809_test2 {
277   template<typename T> struct Err { typename T::error n; };  // expected-error{{type 'void *' cannot be used prior to '::' because it has no members}}
278   struct S {
279     template<typename T> typename Err<T>::type method(T);  // expected-note{{in instantiation of template class 'b6956809_test2::Err<void *>' requested here}}
280     template<typename T> int method(T *);  // expected-note{{'method' declared here}}
281   };
282 
test()283   void test() {
284     S s;
285     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 *]}}
286   }
287 }
288 
289 namespace PR12951 {
290 // If there are two corrections that have the same identifier and edit distance
291 // and only differ by their namespaces, don't suggest either as a correction
292 // since both are equally likely corrections.
293 namespace foobar { struct Thing {}; }
294 namespace bazquux { struct Thing {}; }
f()295 void f() { Thing t; } // expected-error{{unknown type name 'Thing'}}
296 }
297 
298 namespace bogus_keyword_suggestion {
test()299 void test() {
300    status = "OK";  // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
301    return status;  // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
302  }
303 }
304 
305 namespace PR13387 {
306 struct A {
307   void CreateFoo(float, float);
308   void CreateBar(float, float);
309 };
310 struct B : A {
311   using A::CreateFoo; // expected-note {{'CreateFoo' declared here}}
312   void CreateFoo(int, int);  // expected-note {{'CreateFoo' declared here}}
313 };
f(B & x)314 void f(B &x) {
315   x.Createfoo(0,0);  // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}
316   x.Createfoo(0.f,0.f);  // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}
317 }
318 }
319 
320 namespace using_decl {
321   namespace somewhere { int foobar; }
322   using somewhere::foobar; // expected-note {{declared here}}
323   int k = goobar; // expected-error {{did you mean 'foobar'?}}
324 }
325 
326 struct DataStruct {void foo();};
327 struct T {
328  DataStruct data_struct;
329  void f();
330 };
331 // should be void T::f();
f()332 void f() {
333  data_struct->foo();  // expected-error-re{{use of undeclared identifier 'data_struct'{{$}}}}
334 }
335 
336 namespace PR12287 {
337 class zif {
338   void nab(int);
339 };
340 void nab();  // expected-note{{'::PR12287::nab' declared here}}
nab(int)341 void zif::nab(int) {
342   nab();  // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::PR12287::nab'?}}
343 }
344 }
345 
346 namespace TemplateFunction {
347 template <class T>
fnA(T)348 void fnA(T) { }  // expected-note {{'::TemplateFunction::fnA' declared here}}
349 
350 template <class T>
fnB(T)351 void fnB(T) { }  // expected-note {{'::TemplateFunction::fnB' declared here}}
352 
353 class Foo {
354  public:
fnA(int,int)355   void fnA(int, int) {}
fnB()356   void fnB() {}
357 };
358 
test(Foo F,int num)359 void test(Foo F, int num) {
360   F.fnA(num);  // expected-error {{too few arguments to function call, expected 2, have 1; did you mean '::TemplateFunction::fnA'?}}
361   F.fnB(num);  // expected-error {{too many arguments to function call, expected 0, have 1; did you mean '::TemplateFunction::fnB'?}}
362 }
363 }
364 namespace using_suggestion_val_dropped_specifier {
FFF()365 void FFF() {} // expected-note {{'::using_suggestion_val_dropped_specifier::FFF' declared here}}
366 namespace N { }
367 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'?}}
368 }
369 
370 namespace class_member_typo_corrections {
371 class Outer {
372 public:
373   class Inner {};  // expected-note {{'Outer::Inner' declared here}}
374   Inner MyMethod(Inner arg);
375 };
376 
MyMethod(Inner arg)377 Inner Outer::MyMethod(Inner arg) {  // expected-error {{unknown type name 'Inner'; did you mean 'Outer::Inner'?}}
378   return Inner();
379 }
380 
381 class Result {
382 public:
383   enum ResultType {
384     ENTITY,  // expected-note {{'Result::ENTITY' declared here}}
385     PREDICATE,  // expected-note {{'Result::PREDICATE' declared here}}
386     LITERAL  // expected-note {{'Result::LITERAL' declared here}}
387   };
388 
389   ResultType type();
390 };
391 
test()392 void test() {
393   Result result_cell;
394   switch (result_cell.type()) {
395   case ENTITY:  // expected-error {{use of undeclared identifier 'ENTITY'; did you mean 'Result::ENTITY'?}}
396   case LITERAL:  // expected-error {{use of undeclared identifier 'LITERAL'; did you mean 'Result::LITERAL'?}}
397   case PREDICAT:  // expected-error {{use of undeclared identifier 'PREDICAT'; did you mean 'Result::PREDICATE'?}}
398     break;
399   }
400 }
401 
402 class Figure {
403   enum ResultType {
404     SQUARE,
405     TRIANGLE,
406     CIRCLE
407   };
408 
409 public:
410   ResultType type();
411 };
412 
testAccess()413 void testAccess() {
414   Figure obj;
415   switch (obj.type()) {
416   case SQUARE:  // expected-error-re {{use of undeclared identifier 'SQUARE'{{$}}}}
417   case TRIANGLE:  // expected-error-re {{use of undeclared identifier 'TRIANGLE'{{$}}}}
418   case CIRCE:  // expected-error-re {{use of undeclared identifier 'CIRCE'{{$}}}}
419     break;
420   }
421 }
422 }
423 
424 long readline(const char *, char *, unsigned long);
assign_to_unknown_var()425 void assign_to_unknown_var() {
426     deadline_ = 1;  // expected-error-re {{use of undeclared identifier 'deadline_'{{$}}}}
427 }
428 
429 namespace no_ns_before_dot {
430 namespace re2 {}
test()431 void test() {
432     req.set_check(false);  // expected-error-re {{use of undeclared identifier 'req'{{$}}}}
433 }
434 }
435 
436 namespace PR17394 {
437   class A {
438   protected:
439     long zzzzzzzzzz;
440   };
441   class B : private A {};
442   B zzzzzzzzzy<>; // expected-error {{template specialization requires 'template<>'}} expected-error {{no variable template matches specialization}}
443 }
444 
445 namespace correct_fields_in_member_funcs {
446 struct S {
447   int my_member;  // expected-note {{'my_member' declared here}}
fcorrect_fields_in_member_funcs::S448   void f() { my_menber = 1; }  // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}}
449 };
450 }
451 
452 namespace PR17019 {
453   template<class F>
454   struct evil {
evilPR17019::evil455     evil(F de) {  // expected-note {{'de' declared here}}
456       de_;  // expected-error {{use of undeclared identifier 'de_'; did you mean 'de'?}} \
457             // expected-warning {{expression result unused}}
458     }
~evilPR17019::evil459     ~evil() {
460       de_->bar()  // expected-error {{use of undeclared identifier 'de_'}}
461     }
462   };
463 
meow()464   void meow() {
465     evil<int> Q(0); // expected-note {{in instantiation of member function}}
466   }
467 }
468 
469 namespace fix_class_name_qualifier {
470 class MessageHeaders {};
471 class MessageUtils {
472  public:
473   static void ParseMessageHeaders(int, int); // expected-note {{'MessageUtils::ParseMessageHeaders' declared here}}
474 };
475 
test()476 void test() {
477   // No, we didn't mean to call MessageHeaders::MessageHeaders.
478   MessageHeaders::ParseMessageHeaders(5, 4); // expected-error {{no member named 'ParseMessageHeaders' in 'fix_class_name_qualifier::MessageHeaders'; did you mean 'MessageUtils::ParseMessageHeaders'?}}
479 }
480 }
481 
482 namespace PR18213 {  // expected-note {{'PR18213' declared here}}
483 struct WrapperInfo {
484   int i;
485 };
486 
487 template <typename T> struct Wrappable {
488   static WrapperInfo kWrapperInfo;
489 };
490 
491 // Note the space before "::PR18213" is intended and needed, as it highlights
492 // the actual typo, which is the leading "::".
493 // TODO: Suggest removing the "::" from "::PR18213" (the right correction)
494 // instead of incorrectly suggesting dropping "PR18213::WrapperInfo::".
495 template <>
496 PR18213::WrapperInfo ::PR18213::Wrappable<int>::kWrapperInfo = { 0 };  // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \
497                                                                        // expected-error {{C++ requires a type specifier for all declarations}}
498 }
499 
500 namespace PR18651 {
501 struct {
502   int x;
503 } a, b;
504 
505 int y = x;  // expected-error-re {{use of undeclared identifier 'x'{{$}}}}
506 }
507 
508 namespace PR18685 {
509 template <class C, int I, int J>
510 class SetVector {
511  public:
SetVector()512   SetVector() {}
513 };
514 
515 template <class C, int I>
516 class SmallSetVector : public SetVector<C, I, 8> {};
517 
518 class foo {};
519 SmallSetVector<foo*, 2> fooSet;
520 }
521 
522 PR18685::BitVector Map;  // expected-error-re {{no type named 'BitVector' in namespace 'PR18685'{{$}}}}
523 
524 namespace shadowed_template {
525 template <typename T> class Fizbin {};  // expected-note {{'::shadowed_template::Fizbin' declared here}}
526 class Baz {
527    int Fizbin;
528    Fizbin<int> qux; // expected-error {{no template named 'Fizbin'; did you mean '::shadowed_template::Fizbin'?}}
529 };
530 }
531 
532 namespace no_correct_template_id_to_non_template {
533   struct Frobnatz {}; // expected-note {{declared here}}
534   Frobnats fn; // expected-error {{unknown type name 'Frobnats'; did you mean 'Frobnatz'?}}
535   Frobnats<int> fni; // expected-error-re {{no template named 'Frobnats'{{$}}}}
536 }
537 
538 namespace PR18852 {
func()539 void func() {
540   struct foo {
541     void barberry() {}
542   };
543   barberry();  // expected-error-re {{use of undeclared identifier 'barberry'{{$}}}}
544 }
545 
546 class Thread {
547  public:
548   void Start();
549   static void Stop();  // expected-note {{'Thread::Stop' declared here}}
550 };
551 
552 class Manager {
553  public:
554   void Start(int);  // expected-note {{'Start' declared here}}
555   void Stop(int);  // expected-note {{'Stop' declared here}}
556 };
557 
test(Manager * m)558 void test(Manager *m) {
559   // Don't suggest Thread::Start as a correction just because it has the same
560   // (unqualified) name and accepts the right number of args; this is a method
561   // call on an object in an unrelated class.
562   m->Start();  // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
563   m->Stop();  // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
564   Stop();  // expected-error {{use of undeclared identifier 'Stop'; did you mean 'Thread::Stop'?}}
565 }
566 
567 }
568 
569 namespace std {
570 class bernoulli_distribution {
571  public:
572   double p() const;
573 };
574 }
test()575 void test() {
576   // Make sure that typo correction doesn't suggest changing 'p' to
577   // 'std::bernoulli_distribution::p' as that is most likely wrong.
578   if (p)  // expected-error-re {{use of undeclared identifier 'p'{{$}}}}
579     return;
580 }
581 
582 namespace PR19681 {
583   struct TypoA {};
584   struct TypoB {
585     void test();
586   private:
587     template<typename T> void private_memfn(T);  // expected-note{{declared here}}
588   };
test()589   void TypoB::test() {
590     // FIXME: should suggest 'PR19681::TypoB::private_memfn' instead of '::PR19681::TypoB::private_memfn'
591     (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'?}}
592   }
593 }
594 
595 namespace testWantFunctionLikeCasts {
test(bool a)596   long test(bool a) {
597     if (a)
598       return struc(5.7);  // expected-error-re {{use of undeclared identifier 'struc'{{$}}}}
599     else
600       return lon(8.0);  // expected-error {{use of undeclared identifier 'lon'; did you mean 'long'?}}
601   }
602 }
603 
604 namespace testCXXDeclarationSpecifierParsing {
605 namespace test {
606   struct SomeSettings {};  // expected-note {{'test::SomeSettings' declared here}}
607 }
608 class Test {};
bar()609 int bar() {
610   Test::SomeSettings some_settings; // expected-error {{no type named 'SomeSettings' in 'testCXXDeclarationSpecifierParsing::Test'; did you mean 'test::SomeSettings'?}}
611 }
612 }
613 
614 namespace testIncludeTypeInTemplateArgument {
615 template <typename T, typename U>
616 void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
617 
618 class AddObservation {}; // expected-note {{declared here}}
bar1()619 int bar1() {
620   // should resolve to a class.
621   foo<AddObservationFn, int>(); // expected-error {{unknown type name 'AddObservationFn'; did you mean 'AddObservation'?}}
622 
623   // should not resolve to a class.
624   foo(AddObservationFn, 1);    // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$}}}}
625   int a = AddObservationFn, b; // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$}}}}
626 
627   int AddObservation; // expected-note 3{{declared here}}
628   // should resolve to a local variable.
629   foo(AddObservationFn, 1);    // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
630   int c = AddObservationFn, d; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}}
631 
632   // FIXME: would be nice to not resolve to a variable.
633   foo<AddObservationFn, int>(); // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} \
634                                    expected-error {{no matching function for call}}
635 }
636 } // namespace testIncludeTypeInTemplateArgument
637 
638 namespace testNoCrashOnNullNNSTypoCorrection {
639 int AddObservation();
640 template <typename T, typename... Args>
641 class UsingImpl {};
642 class AddObservation { // expected-note {{declared here}}
643   using Using =
644       // should resolve to a class.
645       UsingImpl<AddObservationFn, const int>; // expected-error {{unknown type name 'AddObservationFn'; did you mean}}
646 };
647 } // namespace testNoCrashOnNullNNSTypoCorrection
648 
649 namespace testNonStaticMemberHandling {
650 struct Foo {
651   bool usesMetadata;  // expected-note {{'usesMetadata' declared here}}
652 };
test(Foo f)653 int test(Foo f) {
654   if (UsesMetadata)  // expected-error-re {{use of undeclared identifier 'UsesMetadata'{{$}}}}
655     return 5;
656   if (f.UsesMetadata)  // expected-error {{no member named 'UsesMetadata' in 'testNonStaticMemberHandling::Foo'; did you mean 'usesMetadata'?}}
657     return 11;
658   return 0;
659 }
660 };
661 
662 namespace testMemberExprDeclarationNameInfo {
663   // The AST should only have the corrected name with no mention of 'data_'.
664   void f(int);
665   struct S {
666     int data;  // expected-note 2{{'data' declared here}}
m_fn1testMemberExprDeclarationNameInfo::S667     void m_fn1() {
668       data_  // expected-error {{use of undeclared identifier 'data_'}}
669           [] =  // expected-error {{expected expression}}
670           f(data_);  // expected-error {{use of undeclared identifier 'data_'}}
671     }
672   };
673 }
674 
675 namespace testArraySubscriptIndex {
676   struct S {
677     int data;  // expected-note {{'data' declared here}}
m_fn1testArraySubscriptIndex::S678     void m_fn1() {
679       (+)[data_];  // expected-error{{expected expression}} expected-error {{use of undeclared identifier 'data_'; did you mean 'data'}}
680     }
681   };
682 }
683 
684 namespace crash_has_include {
685 int has_include(int); // expected-note {{'has_include' declared here}}
686 // expected-error@+1 {{'__has_include' must be used within a preprocessing directive}}
687 int foo = __has_include(42); // expected-error {{use of undeclared identifier '__has_include'; did you mean 'has_include'?}}
688 }
689 
690 namespace PR24781_using_crash {
691 namespace A {
692 namespace B {
693 class Foofoo {};  // expected-note {{'A::B::Foofoo' declared here}}
694 }
695 }
696 
697 namespace C {
698 namespace D {
699 class Bar : public A::B::Foofoo {};
700 }
701 }
702 
703 using C::D::Foofoo;  // expected-error {{no member named 'Foofoo' in namespace 'PR24781_using_crash::C::D'; did you mean 'A::B::Foofoo'?}}
704 }
705 
706 int d = ? L : d; // expected-error {{expected expression}} expected-error {{undeclared identifier}}
707 
708 struct B0 {
709   int : 0 |         // expected-error {{invalid operands to binary expression}}
710       (struct B0)e; // expected-error {{use of undeclared identifier}}
711 };
712 
713 namespace {
714 struct a0is0 {};
715 struct b0is0 {};
g()716 int g() {
717   0 [
718       sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
719 };
720 }
721 
722 namespace avoidRedundantRedefinitionErrors {
723 class Class {
724   void function(int pid); // expected-note {{'function' declared here}}
725 };
726 
function2(int pid)727 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'?}}
728 }
729 
730 // Expected no redefinition error here.
function(int pid)731 void Class::function(int pid) { // expected-note {{previous definition is here}}
732 }
733 
function(int pid)734 void Class::function(int pid) { // expected-error {{redefinition of 'function'}}
735 }
736 
737 namespace ns {
738 void create_test(); // expected-note {{'create_test' declared here}}
739 }
740 
create_test2()741 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'?}}
742 }
743 
744 // Expected no redefinition error here.
create_test()745 void ns::create_test() {
746 }
747 }
748 
749 namespace PR46487 {
750   bool g_var_bool; // expected-note {{here}}
751   const char g_volatile_char = 5; // expected-note {{here}}
752   // FIXME: We shouldn't suggest a typo-correction to 'g_var_bool' here,
753   // because it doesn't make the expression valid.
754   // expected-error@+2 {{did you mean 'g_var_bool'}}
755   // expected-error@+1 {{assigning to 'bool' from incompatible type 'void'}}
756   enum : decltype((g_var_long = throw))::a {
757     b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
758   };
759 }
760