Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions %s
      2 
      3 namespace fizbin { class Foobar {}; } // expected-note 2 {{'fizbin::Foobar' declared here}} \
      4                                       // expected-note {{'Foobar' declared here}}
      5 Foobar *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'?}}
      7 fizbin::Foobar *my_foo = new fizbin::FooBar; // expected-error{{no type named 'FooBar' in namespace 'fizbin'; did you mean 'Foobar'?}}
      8 
      9 namespace barstool { int toFoobar() { return 1; } } // expected-note 3 {{'barstool::toFoobar' declared here}}
     10 int Double(int x) { return x + x; }
     11 void empty() {
     12   Double(toFoobar()); // expected-error{{use of undeclared identifier 'toFoobar'; did you mean 'barstool::toFoobar'?}}
     13 }
     14 
     15 namespace 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 }
     25 void 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 
     38 void Alt() {
     39   Cleck(); // expected-error{{use of undeclared identifier 'Cleck'; did you mean 'Check'?}}
     40 }
     41 
     42 namespace 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 
     52 namespace realstd {
     53   inline namespace __1 {
     54     class mylinkedlist { /* ... */ }; // expected-note 2 {{'realstd::mylinkedlist' declared here}}
     55   }
     56 
     57   class linkedlist { /* ... */ };
     58 }
     59 
     60 void 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 // Test case from http://llvm.org/bugs/show_bug.cgi?id=10318
     66 namespace llvm {
     67  template <typename T> class GraphWriter {}; // expected-note 3{{declared here}}
     68 }
     69 
     70 struct S {};
     71 void bar() {
     72  GraphWriter<S> x; //expected-error{{no template named 'GraphWriter'; did you mean 'llvm::GraphWriter'?}}
     73  (void)new llvm::GraphWriter; // expected-error {{use of class template 'llvm::GraphWriter' requires template arguments}}
     74  (void)new llvm::Graphwriter<S>; // expected-error {{no template named 'Graphwriter' in namespace 'llvm'; did you mean 'GraphWriter'?}}
     75 }
     76 
     77 // If namespace prefixes and character edits have the same weight, correcting
     78 // "fimish" to "N::famish" would have the same edit distance as correcting
     79 // "fimish" to "Finish". The result would be no correction being suggested
     80 // unless one of the corrections is given precedence (e.g. by filtering out
     81 // suggestions with added namespace qualifiers).
     82 namespace N { void famish(int); }
     83 void Finish(int); // expected-note {{'Finish' declared here}}
     84 void Start() {
     85   fimish(7); // expected-error {{use of undeclared identifier 'fimish'; did you mean 'Finish'?}}
     86 }
     87 
     88 // But just eliminating the corrections containing added namespace qualifiers
     89 // won't work if both of the tied corrections have namespace qualifiers added.
     90 namespace N {
     91 void someCheck(int); // expected-note {{'N::someCheck' declared here}}
     92 namespace O { void somechock(int); }
     93 }
     94 void confusing() {
     95   somechick(7); // expected-error {{use of undeclared identifier 'somechick'; did you mean 'N::someCheck'?}}
     96 }
     97 
     98 
     99 class Message {};
    100 namespace extra {
    101   namespace util {
    102     namespace MessageUtils {
    103       bool Equivalent(const Message&, const Message&); // expected-note {{'extra::util::MessageUtils::Equivalent' declared here}} \
    104                                                        // expected-note {{'::extra::util::MessageUtils::Equivalent' declared here}}
    105     }
    106   }
    107 }
    108 namespace util { namespace MessageUtils {} }
    109 bool nstest () {
    110   Message a, b;
    111   return util::MessageUtils::Equivalent(a, b); // expected-error {{no member named 'Equivalent' in namespace 'util::MessageUtils'; did you mean 'extra::util::MessageUtils::Equivalent'?}}
    112 }
    113 
    114 namespace util {
    115   namespace extra {
    116     bool nstest () {
    117       Message a, b;
    118       return MessageUtils::Equivalent(a, b); // expected-error {{no member named 'Equivalent' in namespace 'util::MessageUtils'; did you mean '::extra::util::MessageUtils::Equivalent'?}}
    119     }
    120   }
    121 }
    122