Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / typo-correction.cpp
blobc262a62f0cb9cf87e77175b4450424c081e6005a
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
4 namespace PR21817{
5 int a(-rsing[2]); // expected-error {{undeclared identifier 'rsing'; did you mean 'using'?}}
6 // expected-error@-1 {{expected expression}}
9 struct errc {
10 int v_;
11 operator int() const {return v_;}
14 class error_condition
16 int _val_;
17 public:
18 error_condition() : _val_(0) {}
20 error_condition(int _val)
21 : _val_(_val) {}
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);
35 inline error_condition make_error_condition(errc _e) {
36 return error_condition(static_cast<int>(_e));
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'?}}
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'?}}
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'?}}
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;
71 double FieldA; // expected-note{{'FieldA' declared here}}
73 st var = { .fielda = 0.0 }; // expected-error{{field designator 'fielda' does not refer to any field in type 'st'; did you mean 'FieldA'?}}
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 {};
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'?}}
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'?}}
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}}
97 unknown_type_test::stream_out out; // expected-error{{no type named 'stream_out' in namespace 'unknown_type_test'; did you mean 'StreamOut'?}}
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'?}}
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'?}}
114 // Test the typo-correction callback in Sema::DiagnoseInvalidRedeclaration.
115 struct BaseDecl {
116 void add_in(int i);
118 struct TestRedecl : public BaseDecl {
119 void add_it(int i); // expected-note{{'add_it' declared here}}
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'?}}
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}}
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'}}
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'}}
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'}}
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'}}
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);
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'}}
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}}
183 class ClashTool {
184 bool HaveConstructExpr();
185 template <class T> T* getExprAs();
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'?}}
193 namespace test1 {
194 struct S {
195 struct Foobar *f; // expected-note{{'Foobar' declared here}}
197 test1::FooBar *b; // expected-error{{no type named 'FooBar' in namespace 'test1'; did you mean 'Foobar'?}}
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'}}
207 namespace PR13051 {
208 template<typename T> struct S {
209 template<typename U> void f();
210 operator bool() const;
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}}
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'?}}
225 inf f(doulbe); // expected-error{{'int'}} expected-error{{'double'}}
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'?}}
235 namespace outer {
236 void somefunc(); // expected-note{{'::outer::somefunc' declared here}}
237 void somefunc(int, int); // expected-note{{'::outer::somefunc' declared here}}
239 namespace inner {
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'?}}
247 namespace b6956809_test1 {
248 struct A {};
249 struct B {};
251 struct S1 {
252 void method(A*); // no note here
253 void method(B*); // expected-note{{'method' declared here}}
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'}}
262 struct S2 {
263 S2();
264 void method(A*) const;
265 private:
266 void method(B*);
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'{{$}}}}
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}}
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 *]}}
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 {}; }
295 void f() { Thing t; } // expected-error{{unknown type name 'Thing'}}
298 namespace bogus_keyword_suggestion {
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'{{$}}}}
305 namespace PR13387 {
306 struct A {
307 void CreateFoo(float, float);
308 void CreateBar(float, float);
310 struct B : A {
311 using A::CreateFoo; // expected-note {{'CreateFoo' declared here}}
312 void CreateFoo(int, int); // expected-note {{'CreateFoo' declared here}}
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'?}}
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'?}}
326 struct DataStruct {void foo();};
327 struct T {
328 DataStruct data_struct;
329 void f();
331 // should be void T::f();
332 void f() {
333 data_struct->foo(); // expected-error-re{{use of undeclared identifier 'data_struct'{{$}}}}
336 namespace PR12287 {
337 class zif {
338 void nab(int);
340 void nab(); // expected-note{{'::PR12287::nab' declared here}}
341 void zif::nab(int) {
342 nab(); // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::PR12287::nab'?}}
346 namespace TemplateFunction {
347 template <class T>
348 void fnA(T) { } // expected-note {{'::TemplateFunction::fnA' declared here}}
350 template <class T>
351 void fnB(T) { } // expected-note {{'::TemplateFunction::fnB' declared here}}
353 class Foo {
354 public:
355 void fnA(int, int) {}
356 void fnB() {}
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'?}}
364 namespace using_suggestion_val_dropped_specifier {
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'?}}
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);
377 Inner Outer::MyMethod(Inner arg) { // expected-error {{unknown type name 'Inner'; did you mean 'Outer::Inner'?}}
378 return Inner();
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}}
389 ResultType type();
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;
402 class Figure {
403 enum ResultType {
404 SQUARE,
405 TRIANGLE,
406 CIRCLE
409 public:
410 ResultType type();
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;
424 long readline(const char *, char *, unsigned long);
425 void assign_to_unknown_var() {
426 deadline_ = 1; // expected-error-re {{use of undeclared identifier 'deadline_'{{$}}}}
429 namespace no_ns_before_dot {
430 namespace re2 {}
431 void test() {
432 req.set_check(false); // expected-error-re {{use of undeclared identifier 'req'{{$}}}}
436 namespace PR17394 {
437 class A {
438 protected:
439 long zzzzzzzzzz;
441 class B : private A {};
442 B zzzzzzzzzy<>; // expected-error {{template specialization requires 'template<>'}} expected-error {{no variable template matches specialization}}
445 namespace correct_fields_in_member_funcs {
446 struct S {
447 int my_member; // expected-note {{'my_member' declared here}}
448 void f() { my_menber = 1; } // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}}
452 namespace PR17019 {
453 template<class F>
454 struct evil {
455 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}}
459 ~evil() {
460 de_->bar() // expected-error {{use of undeclared identifier 'de_'}}
464 void meow() {
465 evil<int> Q(0); // expected-note {{in instantiation of member function}}
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}}
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'?}}
482 namespace PR18213 { // expected-note {{'PR18213' declared here}}
483 struct WrapperInfo {
484 int i;
487 template <typename T> struct Wrappable {
488 static WrapperInfo kWrapperInfo;
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 {{a type specifier is required for all declarations}}
500 namespace PR18651 {
501 struct {
502 int x;
503 } a, b;
505 int y = x; // expected-error-re {{use of undeclared identifier 'x'{{$}}}}
508 namespace PR18685 {
509 template <class C, int I, int J>
510 class SetVector {
511 public:
512 SetVector() {}
515 template <class C, int I>
516 class SmallSetVector : public SetVector<C, I, 8> {};
518 class foo {};
519 SmallSetVector<foo*, 2> fooSet;
522 PR18685::BitVector Map; // expected-error-re {{no type named 'BitVector' in namespace 'PR18685'{{$}}}}
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'?}}
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'{{$}}}}
538 namespace PR18852 {
539 void func() {
540 struct foo {
541 void barberry() {}
543 barberry(); // expected-error-re {{use of undeclared identifier 'barberry'{{$}}}}
546 class Thread {
547 public:
548 void Start();
549 static void Stop(); // expected-note {{'Thread::Stop' declared here}}
552 class Manager {
553 public:
554 void Start(int); // expected-note {{'Start' declared here}}
555 void Stop(int); // expected-note {{'Stop' declared here}}
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'?}}
569 namespace std {
570 class bernoulli_distribution {
571 public:
572 double p() const;
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;
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}}
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'?}}
595 namespace testWantFunctionLikeCasts {
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'?}}
604 namespace testCXXDeclarationSpecifierParsing {
605 namespace test {
606 struct SomeSettings {}; // expected-note {{'test::SomeSettings' declared here}}
608 class Test {};
609 int bar() {
610 Test::SomeSettings some_settings; // expected-error {{no type named 'SomeSettings' in 'testCXXDeclarationSpecifierParsing::Test'; did you mean 'test::SomeSettings'?}}
614 namespace testIncludeTypeInTemplateArgument {
615 template <typename T, typename U>
616 void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}}
618 class AddObservation {}; // expected-note {{declared here}}
619 int bar1() {
620 // should resolve to a class.
621 foo<AddObservationFn, int>(); // expected-error {{unknown type name 'AddObservationFn'; did you mean 'AddObservation'?}}
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'{{$}}}}
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}}
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}}
636 } // namespace testIncludeTypeInTemplateArgument
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}}
647 } // namespace testNoCrashOnNullNNSTypoCorrection
649 namespace testNonStaticMemberHandling {
650 struct Foo {
651 bool usesMetadata; // expected-note {{'usesMetadata' declared here}}
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;
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}}
667 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_'}}
675 namespace testArraySubscriptIndex {
676 struct S {
677 int data; // expected-note {{'data' declared here}}
678 void m_fn1() {
679 (+)[data_]; // expected-error{{expected expression}} expected-error {{use of undeclared identifier 'data_'; did you mean 'data'}}
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'?}}
690 namespace PR24781_using_crash {
691 namespace A {
692 namespace B {
693 class Foofoo {}; // expected-note {{'A::B::Foofoo' declared here}}
697 namespace C {
698 namespace D {
699 class Bar : public A::B::Foofoo {};
703 using C::D::Foofoo; // expected-error {{no member named 'Foofoo' in namespace 'PR24781_using_crash::C::D'; did you mean 'A::B::Foofoo'?}}
706 int d = ? L : d; // expected-error {{expected expression}} expected-error {{undeclared identifier}}
708 struct B0 {
709 int : 0 | // expected-error {{invalid operands to binary expression}}
710 (struct B0)e; // expected-error {{use of undeclared identifier}}
713 namespace {
714 struct a0is0 {};
715 struct b0is0 {};
716 int g() {
718 sizeof(c0is0)]; // expected-error {{use of undeclared identifier}}
722 namespace avoidRedundantRedefinitionErrors {
723 class Class {
724 void function(int pid); // expected-note {{'function' declared here}}
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'?}}
730 // Expected no redefinition error here.
731 void Class::function(int pid) { // expected-note {{previous definition is here}}
734 void Class::function(int pid) { // expected-error {{redefinition of 'function'}}
737 namespace ns {
738 void create_test(); // expected-note {{'create_test' declared here}}
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'?}}
744 // Expected no redefinition error here.
745 void ns::create_test() {
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 : typename decltype((g_var_long = throw))::a {
757 b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}}
761 namespace PR47272
764 namespace Views {
765 int Take(); // expected-note{{'Views::Take' declared here}}
768 namespace [[deprecated("use Views instead")]] View {
769 using Views::Take;
772 namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked deprecated here}}
773 int pr47272;
776 namespace B {
777 using A::pr47272; // expected-note{{'B::pr47272' declared here}} expected-warning{{'A' is deprecated}}
780 namespace [[deprecated]] C {
781 using A::pr47272;
784 void function() {
785 int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}}
786 int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}}