124 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions %s2 3namespace fizbin { class Foobar {}; } // expected-note 2 {{'fizbin::Foobar' declared here}} \4 // expected-note {{'Foobar' declared here}}5Foobar *my_bar // expected-error{{unknown type name 'Foobar'; did you mean 'fizbin::Foobar'?}}6 = new Foobar; // expected-error{{unknown type name 'Foobar'; did you mean 'fizbin::Foobar'?}}7fizbin::Foobar *my_foo = new fizbin::FooBar; // expected-error{{no type named 'FooBar' in namespace 'fizbin'; did you mean 'Foobar'?}}8 9namespace barstool { int toFoobar() { return 1; } } // expected-note 3 {{'barstool::toFoobar' declared here}}10int Double(int x) { return x + x; }11void empty() {12 Double(toFoobar()); // expected-error{{use of undeclared identifier 'toFoobar'; did you mean 'barstool::toFoobar'?}}13}14 15namespace fizbin {16 namespace baztool { bool toFoobar() { return true; } } // expected-note{{'fizbin::baztool' declared here}}17 namespace nested { bool moreFoobar() { return true; } } // expected-note{{'fizbin::nested::moreFoobar' declared here}}18 namespace nested { bool lessFoobar() { return true; } } // expected-note{{'fizbin::nested' declared here}} \19 // expected-note{{'fizbin::nested::lessFoobar' declared here}}20 class dummy { // expected-note 2 {{'fizbin::dummy' declared here}}21 public:22 static bool morebar() { return false; } // expected-note{{'morebar' declared here}}23 };24}25void Check() { // expected-note{{'Check' declared here}}26 if (toFoobar()) Double(7); // expected-error{{use of undeclared identifier 'toFoobar'; did you mean 'barstool::toFoobar'?}}27 if (noFoobar()) Double(7); // expected-error{{use of undeclared identifier 'noFoobar'; did you mean 'barstool::toFoobar'?}}28 if (moreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'moreFoobar'; did you mean 'fizbin::nested::moreFoobar'}}29 if (lessFoobar()) Double(7); // expected-error{{use of undeclared identifier 'lessFoobar'; did you mean 'fizbin::nested::lessFoobar'?}}30 if (baztool::toFoobar()) Double(7); // expected-error{{use of undeclared identifier 'baztool'; did you mean 'fizbin::baztool'?}}31 if (nested::moreFoobar()) Double(7); // expected-error{{use of undeclared identifier 'nested'; did you mean 'fizbin::nested'?}}32 if (dummy::morebar()) Double(7); // expected-error{{use of undeclared identifier 'dummy'; did you mean 'fizbin::dummy'?}}33 if (dummy::mrebar()) Double(7); // expected-error{{use of undeclared identifier 'dummy'; did you mean 'fizbin::dummy'?}} \34 // expected-error{{no member named 'mrebar' in 'fizbin::dummy'; did you mean 'morebar'?}}35 if (moFoobin()) Double(7); // expected-error{{use of undeclared identifier 'moFoobin'}}36}37 38void Alt() {39 Cleck(); // expected-error{{use of undeclared identifier 'Cleck'; did you mean 'Check'?}}40}41 42namespace N {43 namespace inner {44 class myvector { /* ... */ }; // expected-note{{'inner::myvector' declared here}}45 }46 47 void f() {48 myvector v; // expected-error{{unknown type name 'myvector'; did you mean 'inner::myvector'?}}49 }50}51 52namespace realstd {53 inline namespace __1 {54 class mylinkedlist { /* ... */ }; // expected-note 2 {{'realstd::mylinkedlist' declared here}}55 }56 57 class linkedlist { /* ... */ };58}59 60void f() {61 mylinkedlist v; // expected-error{{unknown type name 'mylinkedlist'; did you mean 'realstd::mylinkedlist'?}}62 nylinkedlist w; // expected-error{{unknown type name 'nylinkedlist'; did you mean 'realstd::mylinkedlist'?}}63}64 65#if __cplusplus < 201703L66// Test case from http://llvm.org/bugs/show_bug.cgi?id=1031867namespace llvm {68 template <typename T> class GraphWriter {}; // expected-note 3{{declared here}}69}70 71struct S {};72void bar() {73 GraphWriter<S> x; //expected-error{{no template named 'GraphWriter'; did you mean 'llvm::GraphWriter'?}}74 (void)new llvm::GraphWriter; // expected-error {{use of class template 'llvm::GraphWriter' requires template arguments}}75 (void)new llvm::Graphwriter<S>; // expected-error {{no template named 'Graphwriter' in namespace 'llvm'; did you mean 'GraphWriter'?}}76}77#endif78 79// If namespace prefixes and character edits have the same weight, correcting80// "fimish" to "N::famish" would have the same edit distance as correcting81// "fimish" to "Finish". The result would be no correction being suggested82// unless one of the corrections is given precedence (e.g. by filtering out83// suggestions with added namespace qualifiers).84namespace N { void famish(int); }85void Finish(int); // expected-note {{'Finish' declared here}}86void Start() {87 fimish(7); // expected-error {{use of undeclared identifier 'fimish'; did you mean 'Finish'?}}88}89 90// But just eliminating the corrections containing added namespace qualifiers91// won't work if both of the tied corrections have namespace qualifiers added.92namespace N {93void someCheck(int); // expected-note {{'N::someCheck' declared here}}94namespace O { void somechock(int); }95}96void confusing() {97 somechick(7); // expected-error {{use of undeclared identifier 'somechick'; did you mean 'N::someCheck'?}}98}99 100 101class Message {};102namespace extra {103 namespace util {104 namespace MessageUtils {105 bool Equivalent(const Message&, const Message&); // expected-note {{'extra::util::MessageUtils::Equivalent' declared here}} \106 // expected-note {{'::extra::util::MessageUtils::Equivalent' declared here}}107 }108 }109}110namespace util { namespace MessageUtils {} }111bool nstest () {112 Message a, b;113 return util::MessageUtils::Equivalent(a, b); // expected-error {{no member named 'Equivalent' in namespace 'util::MessageUtils'; did you mean 'extra::util::MessageUtils::Equivalent'?}}114}115 116namespace util {117 namespace extra {118 bool nstest () {119 Message a, b;120 return MessageUtils::Equivalent(a, b); // expected-error {{no member named 'Equivalent' in namespace 'util::MessageUtils'; did you mean '::extra::util::MessageUtils::Equivalent'?}}121 }122 }123}124