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 8namespace 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. 12namespace foobar { struct Thing {}; } 13namespace bazquux { struct Thing {}; } 14void f() { Thing t; } // expected-error{{unknown type name 'Thing'}} 15} 16 17namespace bogus_keyword_suggestion { 18void 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 24namespace PR13387 { 25struct A { 26 void CreateFoo(float, float); 27 void CreateBar(float, float); 28}; 29struct B : A { 30 using A::CreateFoo; 31 void CreateFoo(int, int); 32}; 33void f(B &x) { 34 x.Createfoo(0,0); // expected-error {{no member named 'Createfoo' in 'PR13387::B'; did you mean 'CreateFoo'?}} 35} 36} 37 38struct DataStruct {void foo();}; 39struct T { 40 DataStruct data_struct; 41 void f(); 42}; 43// should be void T::f(); 44void f() { 45 data_struct->foo(); // expected-error-re{{use of undeclared identifier 'data_struct'{{$}}}} 46} 47 48namespace PR12287 { 49class zif { 50 void nab(int); 51}; 52void nab(); // expected-note{{'::PR12287::nab' declared here}} 53void 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 58namespace TemplateFunction { 59template <class T> 60void A(T) { } // expected-note {{'::TemplateFunction::A' declared here}} 61 62template <class T> 63void B(T) { } // expected-note {{'::TemplateFunction::B' declared here}} 64 65class Foo { 66 public: 67 void A(int, int) {} 68 void B() {} 69}; 70 71void 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} 76namespace using_suggestion_val_dropped_specifier { 77void FFF() {} // expected-note {{'::using_suggestion_val_dropped_specifier::FFF' declared here}} 78namespace N { } 79using 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 82namespace class_member_typo_corrections { 83class Outer { 84public: 85 class Inner {}; // expected-note {{'Outer::Inner' declared here}} 86 Inner MyMethod(Inner arg); 87}; 88 89Inner Outer::MyMethod(Inner arg) { // expected-error {{unknown type name 'Inner'; did you mean 'Outer::Inner'?}} 90 return Inner(); 91} 92 93class Result { 94public: 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 104void 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 114class Figure { 115 enum ResultType { 116 SQUARE, 117 TRIANGLE, 118 CIRCLE 119 }; 120 121public: 122 ResultType type(); 123}; 124 125void 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 136long readline(const char *, char *, unsigned long); 137void assign_to_unknown_var() { 138 deadline_ = 1; // expected-error-re {{use of undeclared identifier 'deadline_'{{$}}}} 139} 140 141namespace no_ns_before_dot { 142namespace re2 {} 143void test() { 144 req.set_check(false); // expected-error-re {{use of undeclared identifier 'req'{{$}}}} 145} 146} 147 148namespace 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 157namespace correct_fields_in_member_funcs { 158struct S { 159 int my_member; // expected-note {{'my_member' declared here}} 160 void f() { my_menber = 1; } // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}} 161}; 162} 163 164namespace PR17019 { 165 template<class F> 166 struct evil { 167 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 } 171 ~evil() { 172 de_->bar() // expected-error {{use of undeclared identifier 'de_'}} 173 } 174 }; 175 176 void meow() { 177 evil<int> Q(0); // expected-note {{in instantiation of member function}} 178 } 179} 180 181namespace fix_class_name_qualifier { 182class MessageHeaders {}; 183class MessageUtils { 184 public: 185 static void ParseMessageHeaders(int, int); // expected-note {{'MessageUtils::ParseMessageHeaders' declared here}} 186}; 187 188void 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 194namespace PR18213 { // expected-note {{'PR18213' declared here}} 195struct WrapperInfo { 196 int i; 197}; 198 199template <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::". 207template <> 208PR18213::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 212namespace PR18651 { 213struct { 214 int x; 215} a, b; 216 217int y = x; // expected-error-re {{use of undeclared identifier 'x'{{$}}}} 218} 219 220namespace PR18685 { 221template <class C, int I, int J> 222class SetVector { 223 public: 224 SetVector() {} 225}; 226 227template <class C, int I> 228class SmallSetVector : public SetVector<C, I, 8> {}; 229 230class foo {}; 231SmallSetVector<foo*, 2> fooSet; 232} 233 234PR18685::BitVector Map; // expected-error-re {{no type named 'BitVector' in namespace 'PR18685'{{$}}}} 235 236namespace shadowed_template { 237template <typename T> class Fizbin {}; // expected-note {{'::shadowed_template::Fizbin' declared here}} 238class 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 247namespace PR18852 { 248void func() { 249 struct foo { 250 void bar() {} 251 }; 252 bar(); // expected-error-re {{use of undeclared identifier 'bar'{{$}}}} 253} 254 255class Thread { 256 public: 257 void Start(); 258 static void Stop(); // expected-note {{'Thread::Stop' declared here}} 259}; 260 261class Manager { 262 public: 263 void Start(int); // expected-note {{'Start' declared here}} 264 void Stop(int); // expected-note {{'Stop' declared here}} 265}; 266 267void 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 278namespace std { 279class bernoulli_distribution { 280 public: 281 double p() const; 282}; 283} 284void 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 291namespace 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 }; 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