• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-c++11-extensions %s
2 //
3 // FIXME: This file is overflow from test/SemaCXX/typo-correction.cpp due to a
4 // hard-coded limit of 20 different typo corrections Sema::CorrectTypo will
5 // attempt within a single file (which is to avoid having very broken files take
6 // minutes to finally be rejected by the parser).
7 
8 namespace PR12951 {
9 // If there are two corrections that have the same identifier and edit distance
10 // and only differ by their namespaces, don't suggest either as a correction
11 // since both are equally likely corrections.
12 namespace foobar { struct Thing {}; }
13 namespace bazquux { struct Thing {}; }
f()14 void f() { Thing t; } // expected-error{{unknown type name 'Thing'}}
15 }
16 
17 namespace bogus_keyword_suggestion {
test()18 void test() {
19    status = "OK";  // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
20    return status;  // expected-error-re {{use of undeclared identifier 'status'{{$}}}}
21  }
22 }
23 
24 namespace PR13387 {
25 struct A {
26   void CreateFoo(float, float);
27   void CreateBar(float, float);
28 };
29 struct B : A {
30   using A::CreateFoo;
31   void CreateFoo(int, int);
32 };
f(B & x)33 void f(B &x) {
34   x.Createfoo(0,0);  // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}}
35 }
36 }
37 
38 struct DataStruct {void foo();};
39 struct T {
40  DataStruct data_struct;
41  void f();
42 };
43 // should be void T::f();
f()44 void f() {
45  data_struct->foo();  // expected-error-re{{use of undeclared identifier 'data_struct'{{$}}}}
46 }
47 
48 namespace PR12287 {
49 class zif {
50   void nab(int);
51 };
52 void nab();  // expected-note{{'::PR12287::nab' declared here}}
nab(int)53 void zif::nab(int) {
54   nab();  // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::PR12287::nab'?}}
55 }
56 }
57 
58 namespace TemplateFunction {
59 template <class T>
A(T)60 void A(T) { }  // expected-note {{'::TemplateFunction::A' declared here}}
61 
62 template <class T>
B(T)63 void B(T) { }  // expected-note {{'::TemplateFunction::B' declared here}}
64 
65 class Foo {
66  public:
A(int,int)67   void A(int, int) {}
B()68   void B() {}
69 };
70 
test(Foo F,int num)71 void test(Foo F, int num) {
72   F.A(num);  // expected-error {{too few arguments to function call, expected 2, have 1; did you mean '::TemplateFunction::A'?}}
73   F.B(num);  // expected-error {{too many arguments to function call, expected 0, have 1; did you mean '::TemplateFunction::B'?}}
74 }
75 }
76 namespace using_suggestion_val_dropped_specifier {
FFF()77 void FFF() {} // expected-note {{'::using_suggestion_val_dropped_specifier::FFF' declared here}}
78 namespace N { }
79 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'?}}
80 }
81 
82 namespace class_member_typo_corrections {
83 class Outer {
84 public:
85   class Inner {};  // expected-note {{'Outer::Inner' declared here}}
86   Inner MyMethod(Inner arg);
87 };
88 
MyMethod(Inner arg)89 Inner Outer::MyMethod(Inner arg) {  // expected-error {{unknown type name 'Inner'; did you mean 'Outer::Inner'?}}
90   return Inner();
91 }
92 
93 class Result {
94 public:
95   enum ResultType {
96     ENTITY,  // expected-note {{'Result::ENTITY' declared here}}
97     PREDICATE,  // expected-note {{'Result::PREDICATE' declared here}}
98     LITERAL  // expected-note {{'Result::LITERAL' declared here}}
99   };
100 
101   ResultType type();
102 };
103 
test()104 void test() {
105   Result result_cell;
106   switch (result_cell.type()) {
107   case ENTITY:  // expected-error {{use of undeclared identifier 'ENTITY'; did you mean 'Result::ENTITY'?}}
108   case LITERAL:  // expected-error {{use of undeclared identifier 'LITERAL'; did you mean 'Result::LITERAL'?}}
109   case PREDICAT:  // expected-error {{use of undeclared identifier 'PREDICAT'; did you mean 'Result::PREDICATE'?}}
110     break;
111   }
112 }
113 
114 class Figure {
115   enum ResultType {
116     SQUARE,
117     TRIANGLE,
118     CIRCLE
119   };
120 
121 public:
122   ResultType type();
123 };
124 
testAccess()125 void testAccess() {
126   Figure obj;
127   switch (obj.type()) {  // expected-warning {{enumeration values 'SQUARE', 'TRIANGLE', and 'CIRCLE' not handled in switch}}
128   case SQUARE:  // expected-error-re {{use of undeclared identifier 'SQUARE'{{$}}}}
129   case TRIANGLE:  // expected-error-re {{use of undeclared identifier 'TRIANGLE'{{$}}}}
130   case CIRCE:  // expected-error-re {{use of undeclared identifier 'CIRCE'{{$}}}}
131     break;
132   }
133 }
134 }
135 
136 long readline(const char *, char *, unsigned long);
assign_to_unknown_var()137 void assign_to_unknown_var() {
138     deadline_ = 1;  // expected-error-re {{use of undeclared identifier 'deadline_'{{$}}}}
139 }
140 
141 namespace no_ns_before_dot {
142 namespace re2 {}
test()143 void test() {
144     req.set_check(false);  // expected-error-re {{use of undeclared identifier 'req'{{$}}}}
145 }
146 }
147 
148 namespace PR17394 {
149   class A {
150   protected:
151     long zzzzzzzzzz;
152   };
153   class B : private A {};
154   B zzzzzzzzzy<>; // expected-error {{expected ';' after top level declarator}}{}
155 }
156 
157 namespace correct_fields_in_member_funcs {
158 struct S {
159   int my_member;  // expected-note {{'my_member' declared here}}
fcorrect_fields_in_member_funcs::S160   void f() { my_menber = 1; }  // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}}
161 };
162 }
163 
164 namespace PR17019 {
165   template<class F>
166   struct evil {
evilPR17019::evil167     evil(F de) {  // expected-note {{'de' declared here}}
168       de_;  // expected-error {{use of undeclared identifier 'de_'; did you mean 'de'?}} \
169             // expected-warning {{expression result unused}}
170     }
~evilPR17019::evil171     ~evil() {
172       de_->bar()  // expected-error {{use of undeclared identifier 'de_'}}
173     }
174   };
175 
meow()176   void meow() {
177     evil<int> Q(0); // expected-note {{in instantiation of member function}}
178   }
179 }
180 
181 namespace fix_class_name_qualifier {
182 class MessageHeaders {};
183 class MessageUtils {
184  public:
185   static void ParseMessageHeaders(int, int); // expected-note {{'MessageUtils::ParseMessageHeaders' declared here}}
186 };
187 
test()188 void test() {
189   // No, we didn't mean to call MessageHeaders::MessageHeaders.
190   MessageHeaders::ParseMessageHeaders(5, 4); // expected-error {{no member named 'ParseMessageHeaders' in 'fix_class_name_qualifier::MessageHeaders'; did you mean 'MessageUtils::ParseMessageHeaders'?}}
191 }
192 }
193 
194 namespace PR18213 {  // expected-note {{'PR18213' declared here}}
195 struct WrapperInfo {
196   int i;
197 };
198 
199 template <typename T> struct Wrappable {
200   static WrapperInfo kWrapperInfo;
201 };
202 
203 // Note the space before "::PR18213" is intended and needed, as it highlights
204 // the actual typo, which is the leading "::".
205 // TODO: Suggest removing the "::" from "::PR18213" (the right correction)
206 // instead of incorrectly suggesting dropping "PR18213::WrapperInfo::".
207 template <>
208 PR18213::WrapperInfo ::PR18213::Wrappable<int>::kWrapperInfo = { 0 };  // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \
209                                                                        // expected-error {{C++ requires a type specifier for all declarations}}
210 }
211 
212 namespace PR18651 {
213 struct {
214   int x;
215 } a, b;
216 
217 int y = x;  // expected-error-re {{use of undeclared identifier 'x'{{$}}}}
218 }
219 
220 namespace PR18685 {
221 template <class C, int I, int J>
222 class SetVector {
223  public:
SetVector()224   SetVector() {}
225 };
226 
227 template <class C, int I>
228 class SmallSetVector : public SetVector<C, I, 8> {};
229 
230 class foo {};
231 SmallSetVector<foo*, 2> fooSet;
232 }
233 
234 PR18685::BitVector Map;  // expected-error-re {{no type named 'BitVector' in namespace 'PR18685'{{$}}}}
235 
236 namespace shadowed_template {
237 template <typename T> class Fizbin {};  // expected-note {{'::shadowed_template::Fizbin' declared here}}
238 class Baz {
239    int Fizbin();
240    // TODO: Teach the parser to recover from the typo correction instead of
241    // continuing to treat the template name as an implicit-int declaration.
242    Fizbin<int> qux;  // expected-error {{unknown type name 'Fizbin'; did you mean '::shadowed_template::Fizbin'?}} \
243                      // expected-error {{expected member name or ';' after declaration specifiers}}
244 };
245 }
246 
247 namespace PR18852 {
func()248 void func() {
249   struct foo {
250     void bar() {}
251   };
252   bar();  // expected-error-re {{use of undeclared identifier 'bar'{{$}}}}
253 }
254 
255 class Thread {
256  public:
257   void Start();
258   static void Stop();  // expected-note {{'Thread::Stop' declared here}}
259 };
260 
261 class Manager {
262  public:
263   void Start(int);  // expected-note {{'Start' declared here}}
264   void Stop(int);  // expected-note {{'Stop' declared here}}
265 };
266 
test(Manager * m)267 void test(Manager *m) {
268   // Don't suggest Thread::Start as a correction just because it has the same
269   // (unqualified) name and accepts the right number of args; this is a method
270   // call on an object in an unrelated class.
271   m->Start();  // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
272   m->Stop();  // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}}
273   Stop();  // expected-error {{use of undeclared identifier 'Stop'; did you mean 'Thread::Stop'?}}
274 }
275 
276 }
277 
278 namespace std {
279 class bernoulli_distribution {
280  public:
281   double p() const;
282 };
283 }
test()284 void test() {
285   // Make sure that typo correction doesn't suggest changing 'p' to
286   // 'std::bernoulli_distribution::p' as that is most likely wrong.
287   if (p)  // expected-error-re {{use of undeclared identifier 'p'{{$}}}}
288     return;
289 }
290 
291 namespace PR19681 {
292   struct TypoA {};
293   struct TypoB {
294     void test();
295   private:
296     template<typename T> void private_memfn(T);  // expected-note{{declared here}}
297   };
test()298   void TypoB::test() {
299     // FIXME: should suggest 'PR19681::TypoB::private_memfn' instead of '::PR19681::TypoB::private_memfn'
300     (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'?}}
301   }
302 }
303