[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / missing-namespace-qualifier-typo-corrections.cpp
blob9d05d64ab40621eca56578d437e30ac1192b54d4
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions %s
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'?}}
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'?}}
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}}
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'}}
38 void Alt() {
39 Cleck(); // expected-error{{use of undeclared identifier 'Cleck'; did you mean 'Check'?}}
42 namespace N {
43 namespace inner {
44 class myvector { /* ... */ }; // expected-note{{'inner::myvector' declared here}}
47 void f() {
48 myvector v; // expected-error{{unknown type name 'myvector'; did you mean 'inner::myvector'?}}
52 namespace realstd {
53 inline namespace __1 {
54 class mylinkedlist { /* ... */ }; // expected-note 2 {{'realstd::mylinkedlist' declared here}}
57 class linkedlist { /* ... */ };
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'?}}
65 #if __cplusplus < 201703L
66 // Test case from http://llvm.org/bugs/show_bug.cgi?id=10318
67 namespace llvm {
68 template <typename T> class GraphWriter {}; // expected-note 3{{declared here}}
71 struct S {};
72 void 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'?}}
77 #endif
79 // If namespace prefixes and character edits have the same weight, correcting
80 // "fimish" to "N::famish" would have the same edit distance as correcting
81 // "fimish" to "Finish". The result would be no correction being suggested
82 // unless one of the corrections is given precedence (e.g. by filtering out
83 // suggestions with added namespace qualifiers).
84 namespace N { void famish(int); }
85 void Finish(int); // expected-note {{'Finish' declared here}}
86 void Start() {
87 fimish(7); // expected-error {{use of undeclared identifier 'fimish'; did you mean 'Finish'?}}
90 // But just eliminating the corrections containing added namespace qualifiers
91 // won't work if both of the tied corrections have namespace qualifiers added.
92 namespace N {
93 void someCheck(int); // expected-note {{'N::someCheck' declared here}}
94 namespace O { void somechock(int); }
96 void confusing() {
97 somechick(7); // expected-error {{use of undeclared identifier 'somechick'; did you mean 'N::someCheck'?}}
101 class Message {};
102 namespace 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}}
110 namespace util { namespace MessageUtils {} }
111 bool 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'?}}
116 namespace 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'?}}