| 1 |
// RUN: %clang_cc1 -fspell-checking-limit=0 -verify -Wno-c++11-extensions -fcxx-exceptions %s |
| 2 |
// RUN: %clang_cc1 -fspell-checking-limit=0 -verify -Wno-c++11-extensions -fcxx-exceptions -std=c++20 %s |
| 3 |
|
| 4 |
namespace PR21817{ |
| 5 |
int a(-rsing[2]); // expected-error {{undeclared identifier 'rsing'; did you mean 'using'?}} |
| 6 |
} |
| 7 |
|
| 8 |
struct errc { |
| 9 |
int v_; |
| 10 |
operator int() const {return v_;} |
| 11 |
}; |
| 12 |
|
| 13 |
class error_condition |
| 14 |
{ |
| 15 |
int _val_; |
| 16 |
public: |
| 17 |
error_condition() : _val_(0) {} |
| 18 |
|
| 19 |
error_condition(int _val) |
| 20 |
: _val_(_val) {} |
| 21 |
|
| 22 |
template <class E> |
| 23 |
error_condition(E _e) { |
| 24 |
// make_error_condition must not be typo corrected to error_condition |
| 25 |
// even though the first declaration of make_error_condition has not |
| 26 |
// yet been encountered. This was a bug in the first version of the type |
| 27 |
// name typo correction patch that wasn't noticed until building LLVM with |
| 28 |
// Clang failed. |
| 29 |
*this = make_error_condition(_e); |
| 30 |
} |
| 31 |
|
| 32 |
}; |
| 33 |
|
| 34 |
inline error_condition make_error_condition(errc _e) { |
| 35 |
return error_condition(static_cast<int>(_e)); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
// Prior to the introduction of a callback object to further filter possible |
| 40 |
// typo corrections, this example would not trigger a suggestion as "base_type" |
| 41 |
// is a closer match to "basetype" than is "BaseType" but "base_type" does not |
| 42 |
// refer to a base class or non-static data member. |
| 43 |
struct BaseType { }; |
| 44 |
struct Derived : public BaseType { // expected-note {{base class 'BaseType' specified here}} |
| 45 |
static int base_type; |
| 46 |
Derived() : basetype() {} // expected-error{{initializer 'basetype' does not name a non-static data member or base class; did you mean the base class 'BaseType'?}} |
| 47 |
}; |
| 48 |
|
| 49 |
// Test the improvement from passing a callback object to CorrectTypo in |
| 50 |
// the helper function LookupMemberExprInRecord. |
| 51 |
int get_type(struct Derived *st) { |
| 52 |
return st->Base_Type; // expected-error{{no member named 'Base_Type' in 'Derived'}} |
| 53 |
} |
| 54 |
|
| 55 |
// In this example, somename should not be corrected to the cached correction |
| 56 |
// "some_name" since "some_name" is a class and a namespace name is needed. |
| 57 |
class some_name {}; // expected-note {{'some_name' declared here}} |
| 58 |
somename Foo; // expected-error {{unknown type name 'somename'; did you mean 'some_name'?}} |
| 59 |
namespace SomeName {} // expected-note {{namespace 'SomeName' defined here}} |
| 60 |
using namespace somename; // expected-error {{no namespace named 'somename'; did you mean 'SomeName'?}} |
| 61 |
|
| 62 |
|
| 63 |
// Without the callback object, CorrectTypo would choose "field1" as the |
| 64 |
// correction for "fielda" as it is closer than "FieldA", but that correction |
| 65 |
// would be later discarded by the caller and no suggestion would be given. |
| 66 |
struct st { |
| 67 |
struct { |
| 68 |
int field1; |
| 69 |
}; |
| 70 |
double FieldA; // expected-note{{'FieldA' declared here}} |
| 71 |
}; |
| 72 |
st var = { .fielda = 0.0 }; // expected-error{{field designator 'fielda' does not refer to any field in type 'st'; did you mean 'FieldA'?}} |
| 73 |
|
| 74 |
// Test the improvement from passing a callback object to CorrectTypo in |
| 75 |
// Sema::BuildCXXNestedNameSpecifier. And also for the improvement by doing |
| 76 |
// so in Sema::getTypeName. |
| 77 |
typedef char* another_str; // expected-note{{'another_str' declared here}} |
| 78 |
namespace AnotherStd { // expected-note{{'AnotherStd' declared here}} |
| 79 |
class string {}; |
| 80 |
} |
| 81 |
another_std::string str; // expected-error{{use of undeclared identifier 'another_std'; did you mean 'AnotherStd'?}} |
| 82 |
another_str *cstr = new AnotherStr; // expected-error{{unknown type name 'AnotherStr'; did you mean 'another_str'?}} |
| 83 |
|
| 84 |
// Test the improvement from passing a callback object to CorrectTypo in |
| 85 |
// Sema::ActOnSizeofParameterPackExpr. |
| 86 |
char* TireNames; |
| 87 |
template<typename ...TypeNames> struct count { // expected-note{{parameter pack 'TypeNames' declared here}} |
| 88 |
static const unsigned value = sizeof...(TyreNames); // expected-error{{'TyreNames' does not refer to the name of a parameter pack; did you mean 'TypeNames'?}} |
| 89 |
}; |
| 90 |
|
| 91 |
// Test the typo-correction callback in Sema::DiagnoseUnknownTypeName. |
| 92 |
namespace unknown_type_test { |
| 93 |
class StreamOut {}; // expected-note 2 {{'StreamOut' declared here}} |
| 94 |
long stream_count; // expected-note 2 {{'stream_count' declared here}} |
| 95 |
}; |
| 96 |
unknown_type_test::stream_out out; // expected-error{{no type named 'stream_out' in namespace 'unknown_type_test'; did you mean 'StreamOut'?}} |
| 97 |
|
| 98 |
// Demonstrate a case where using only the cached value returns the wrong thing |
| 99 |
// when the cached value was the result of a previous callback object that only |
| 100 |
// accepts a subset of the current callback object. |
| 101 |
namespace cache_invalidation_test { |
| 102 |
using namespace unknown_type_test; |
| 103 |
void bar(long i); |
| 104 |
void before_caching_classname() { |
| 105 |
bar((stream_out)); // expected-error{{use of undeclared identifier 'stream_out'; did you mean 'stream_count'?}} |
| 106 |
} |
| 107 |
stream_out out; // expected-error{{unknown type name 'stream_out'; did you mean 'StreamOut'?}} |
| 108 |
void after_caching_classname() { |
| 109 |
bar((stream_out)); // expected-error{{use of undeclared identifier 'stream_out'; did you mean 'stream_count'?}} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
// Test the typo-correction callback in Sema::DiagnoseInvalidRedeclaration. |
| 114 |
struct BaseDecl { |
| 115 |
void add_in(int i); |
| 116 |
}; |
| 117 |
struct TestRedecl : public BaseDecl { |
| 118 |
void add_it(int i); // expected-note{{'add_it' declared here}} |
| 119 |
}; |
| 120 |
void TestRedecl::add_in(int i) {} // expected-error{{out-of-line definition of 'add_in' does not match any declaration in 'TestRedecl'; did you mean 'add_it'?}} |
| 121 |
|
| 122 |
// Test the improved typo correction for the Parser::ParseCastExpr => |
| 123 |
// Sema::ActOnIdExpression => Sema::DiagnoseEmptyLookup call path. |
| 124 |
class SomeNetMessage; // expected-note 2{{'SomeNetMessage'}} |
| 125 |
class Message {}; |
| 126 |
void foo(Message&); |
| 127 |
void foo(SomeNetMessage&); |
| 128 |
void doit(void *data) { |
| 129 |
Message somenetmsg; // expected-note{{'somenetmsg' declared here}} |
| 130 |
foo(somenetmessage); // expected-error{{use of undeclared identifier 'somenetmessage'; did you mean 'somenetmsg'?}} |
| 131 |
foo((somenetmessage)data); // expected-error{{unknown type name 'somenetmessage'; did you mean 'SomeNetMessage'?}} expected-error{{incomplete type}} |
| 132 |
} |
| 133 |
|
| 134 |
// Test the typo-correction callback in BuildRecoveryCallExpr. |
| 135 |
// Solves the main issue in PR 9320 of suggesting corrections that take the |
| 136 |
// wrong number of arguments. |
| 137 |
void revoke(const char*); // expected-note 2{{'revoke' declared here}} |
| 138 |
void Test() { |
| 139 |
Invoke(); // expected-error{{use of undeclared identifier 'Invoke'}} |
| 140 |
Invoke("foo"); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'revoke'?}} |
| 141 |
Invoke("foo", "bar"); // expected-error{{use of undeclared identifier 'Invoke'}} |
| 142 |
} |
| 143 |
void Test2(void (*invoke)(const char *, int)) { // expected-note{{'invoke' declared here}} |
| 144 |
Invoke(); // expected-error{{use of undeclared identifier 'Invoke'}} |
| 145 |
Invoke("foo"); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'revoke'?}} |
| 146 |
Invoke("foo", 7); // expected-error{{use of undeclared identifier 'Invoke'; did you mean 'invoke'?}} |
| 147 |
Invoke("foo", 7, 22); // expected-error{{use of undeclared identifier 'Invoke'}} |
| 148 |
} |
| 149 |
|
| 150 |
void provoke(const char *x, bool y=false) {} // expected-note 2{{'provoke' declared here}} |
| 151 |
void Test3() { |
| 152 |
Provoke(); // expected-error{{use of undeclared identifier 'Provoke'}} |
| 153 |
Provoke("foo"); // expected-error{{use of undeclared identifier 'Provoke'; did you mean 'provoke'?}} |
| 154 |
Provoke("foo", true); // expected-error{{use of undeclared identifier 'Provoke'; did you mean 'provoke'?}} |
| 155 |
Provoke("foo", 7, 22); // expected-error{{use of undeclared identifier 'Provoke'}} |
| 156 |
} |
| 157 |
|
| 158 |
// PR 11737 - Don't try to typo-correct the implicit 'begin' and 'end' in a |
| 159 |
// C++11 for-range statement. |
| 160 |
struct R {}; |
| 161 |
bool begun(R); |
| 162 |
void RangeTest() { |
| 163 |
for (auto b : R()) {} // expected-error {{invalid range expression of type 'R'}} |
| 164 |
} |
| 165 |
|
| 166 |
// PR 12019 - Avoid infinite mutual recursion in DiagnoseInvalidRedeclaration |
| 167 |
// by not trying to typo-correct a method redeclaration to declarations not |
| 168 |
// in the current record. |
| 169 |
class Parent { |
| 170 |
void set_types(int index, int value); |
| 171 |
void add_types(int value); |
| 172 |
}; |
| 173 |
class Child: public Parent {}; |
| 174 |
void Child::add_types(int value) {} // expected-error{{out-of-line definition of 'add_types' does not match any declaration in 'Child'}} |
| 175 |
// expected-note@-2{{defined here}} |
| 176 |
|
| 177 |
// Fix the callback based filtering of typo corrections within |
| 178 |
// Sema::ActOnIdExpression by Parser::ParseCastExpression to allow type names as |
| 179 |
// potential corrections for template arguments. |
| 180 |
namespace clash { |
| 181 |
class ConstructExpr {}; // expected-note 2{{'clash::ConstructExpr' declared here}} |
| 182 |
} |
| 183 |
class ClashTool { |
| 184 |
bool HaveConstructExpr(); |
| 185 |
template <class T> T* getExprAs(); |
| 186 |
|
| 187 |
void test() { |
| 188 |
ConstructExpr *expr = // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}} |
| 189 |
getExprAs<ConstructExpr>(); // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}} |
| 190 |
} |
| 191 |
}; |
| 192 |
|
| 193 |
namespace test1 { |
| 194 |
struct S { |
| 195 |
struct Foobar *f; // expected-note{{'Foobar' declared here}} |
| 196 |
}; |
| 197 |
test1::FooBar *b; // expected-error{{no type named 'FooBar' in namespace 'test1'; did you mean 'Foobar'?}} |
| 198 |
} |
| 199 |
|
| 200 |
namespace ImplicitInt { |
| 201 |
void f(int, unsinged); // expected-error{{did you mean 'unsigned'}} |
| 202 |
struct S { |
| 203 |
unsinged : 4; // expected-error{{did you mean 'unsigned'}} |
| 204 |
}; |
| 205 |
} |
| 206 |
|
| 207 |
namespace PR13051 { |
| 208 |
template<typename T> struct S { |
| 209 |
template<typename U> void f(); |
| 210 |
operator bool() const; |
| 211 |
}; |
| 212 |
|
| 213 |
void foo(); // expected-note{{'foo' declared here}} |
| 214 |
void g(void(*)()); |
| 215 |
void g(bool(S<int>::*)() const); |
| 216 |
|
| 217 |
void test() { |
| 218 |
g(&S<int>::tempalte f<int>); // expected-error{{did you mean 'template'?}} |
| 219 |
g(&S<int>::opeartor bool); // expected-error{{did you mean 'operator'?}} |
| 220 |
g(&S<int>::foo); // expected-error{{no member named 'foo' in 'PR13051::S<int>'; did you mean simply 'foo'?}} |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
inf f(doulbe); // expected-error{{'int'}} expected-error{{'double'}} |
| 225 |
|
| 226 |
namespace PR6325 { |
| 227 |
class foo { }; // expected-note{{'foo' declared here}} |
| 228 |
// Note that for this example (pulled from the PR), if keywords are not excluded |
| 229 |
// as correction candidates then no suggestion would be given; correcting |
| 230 |
// 'boo' to 'bool' is the same edit distance as correcting 'boo' to 'foo'. |
| 231 |
class bar : boo { }; // expected-error{{unknown class name 'boo'; did you mean 'foo'?}} |
| 232 |
} |
| 233 |
|
| 234 |
namespace outer { |
| 235 |
void somefunc(); // expected-note{{'::outer::somefunc' declared here}} |
| 236 |
void somefunc(int, int); // expected-note{{'::outer::somefunc' declared here}} |
| 237 |
|
| 238 |
namespace inner { |
| 239 |
void somefunc(int) { |
| 240 |
someFunc(); // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}} |
| 241 |
someFunc(1, 2); // expected-error{{use of undeclared identifier 'someFunc'; did you mean '::outer::somefunc'?}} |
| 242 |
} |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
namespace b6956809_test1 { |
| 247 |
struct A {}; |
| 248 |
struct B {}; |
| 249 |
|
| 250 |
struct S1 { |
| 251 |
void method(A*); // no note here |
| 252 |
void method(B*); |
| 253 |
}; |
| 254 |
|
| 255 |
void test1() { |
| 256 |
B b; |
| 257 |
S1 s; |
| 258 |
s.methodd(&b); // expected-error{{no member named 'methodd' in 'b6956809_test1::S1'}} |
| 259 |
} |
| 260 |
|
| 261 |
struct S2 { |
| 262 |
S2(); |
| 263 |
void method(A*) const; |
| 264 |
private: |
| 265 |
void method(B*); |
| 266 |
}; |
| 267 |
|
| 268 |
void test2() { |
| 269 |
B b; |
| 270 |
const S2 s; |
| 271 |
s.methodd(&b); // expected-error-re{{no member named 'methodd' in 'b6956809_test1::S2'{{$}}}} |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
namespace b6956809_test2 { |
| 276 |
template<typename T> struct Err { typename T::error n; }; |
| 277 |
struct S { |
| 278 |
template<typename T> typename Err<T>::type method(T); |
| 279 |
template<typename T> int method(T *); |
| 280 |
}; |
| 281 |
|
| 282 |
void test() { |
| 283 |
S s; |
| 284 |
int k = s.methodd((void*)0); // expected-error{{no member named 'methodd' in 'b6956809_test2::S'}} |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
namespace PR12951 { |
| 289 |
// If there are two corrections that have the same identifier and edit distance |
| 290 |
// and only differ by their namespaces, don't suggest either as a correction |
| 291 |
// since both are equally likely corrections. |
| 292 |
namespace foobar { struct Thing {}; } |
| 293 |
namespace bazquux { struct Thing {}; } |
| 294 |
void f() { Thing t; } // expected-error{{unknown type name 'Thing'}} |
| 295 |
} |
| 296 |
|
| 297 |
namespace bogus_keyword_suggestion { |
| 298 |
void test() { |
| 299 |
status = "OK"; // expected-error-re {{use of undeclared identifier 'status'{{$}}}} |
| 300 |
return status; // expected-error-re {{use of undeclared identifier 'status'{{$}}}} |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
namespace PR13387 { |
| 305 |
struct A { |
| 306 |
void CreateFoo(float, float); |
| 307 |
void CreateBar(float, float); |
| 308 |
}; |
| 309 |
struct B : A { |
| 310 |
using A::CreateFoo; |
| 311 |
void CreateFoo(int, int); |
| 312 |
}; |
| 313 |
void f(B &x) { |
| 314 |
x.Createfoo(0,0); // expected-error {{no member named 'Createfoo' in 'PR13387::B'}} |
| 315 |
x.Createfoo(0.f,0.f); // expected-error {{no member named 'Createfoo' in 'PR13387::B'}} |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
namespace using_decl { |
| 320 |
namespace somewhere { int foobar; } |
| 321 |
using somewhere::foobar; // expected-note {{declared here}} |
| 322 |
int k = goobar; // expected-error {{did you mean 'foobar'?}} |
| 323 |
} |
| 324 |
|
| 325 |
struct DataStruct {void foo();}; |
| 326 |
struct T { |
| 327 |
DataStruct data_struct; |
| 328 |
void f(); |
| 329 |
}; |
| 330 |
// should be void T::f(); |
| 331 |
void f() { |
| 332 |
data_struct->foo(); // expected-error-re{{use of undeclared identifier 'data_struct'{{$}}}} |
| 333 |
} |
| 334 |
|
| 335 |
namespace PR12287 { |
| 336 |
class zif { |
| 337 |
void nab(int); |
| 338 |
}; |
| 339 |
void nab(); // expected-note{{'::PR12287::nab' declared here}} |
| 340 |
void zif::nab(int) { |
| 341 |
nab(); // expected-error{{too few arguments to function call, expected 1, have 0; did you mean '::PR12287::nab'?}} |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
namespace TemplateFunction { |
| 346 |
template <class T> |
| 347 |
void fnA(T) { } // expected-note {{'::TemplateFunction::fnA' declared here}} |
| 348 |
|
| 349 |
template <class T> |
| 350 |
void fnB(T) { } // expected-note {{'::TemplateFunction::fnB' declared here}} |
| 351 |
|
| 352 |
class Foo { |
| 353 |
public: |
| 354 |
void fnA(int, int) {} |
| 355 |
void fnB() {} |
| 356 |
}; |
| 357 |
|
| 358 |
void test(Foo F, int num) { |
| 359 |
F.fnA(num); // expected-error {{too few arguments to function call, expected 2, have 1; did you mean '::TemplateFunction::fnA'?}} |
| 360 |
F.fnB(num); // expected-error {{too many arguments to function call, expected 0, have 1; did you mean '::TemplateFunction::fnB'?}} |
| 361 |
} |
| 362 |
} |
| 363 |
namespace using_suggestion_val_dropped_specifier { |
| 364 |
void FFF() {} // expected-note {{'::using_suggestion_val_dropped_specifier::FFF' declared here}} |
| 365 |
namespace N { } |
| 366 |
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'?}} |
| 367 |
} |
| 368 |
|
| 369 |
namespace class_member_typo_corrections { |
| 370 |
class Outer { |
| 371 |
public: |
| 372 |
class Inner {}; // expected-note {{'Outer::Inner' declared here}} |
| 373 |
Inner MyMethod(Inner arg); |
| 374 |
}; |
| 375 |
|
| 376 |
Inner Outer::MyMethod(Inner arg) { // expected-error {{unknown type name 'Inner'; did you mean 'Outer::Inner'?}} |
| 377 |
return Inner(); |
| 378 |
} |
| 379 |
|
| 380 |
class Result { |
| 381 |
public: |
| 382 |
enum ResultType { |
| 383 |
ENTITY, // expected-note {{'Result::ENTITY' declared here}} |
| 384 |
PREDICATE, // expected-note {{'Result::PREDICATE' declared here}} |
| 385 |
LITERAL // expected-note {{'Result::LITERAL' declared here}} |
| 386 |
}; |
| 387 |
|
| 388 |
ResultType type(); |
| 389 |
}; |
| 390 |
|
| 391 |
void test() { |
| 392 |
Result result_cell; |
| 393 |
switch (result_cell.type()) { |
| 394 |
case ENTITY: // expected-error {{use of undeclared identifier 'ENTITY'; did you mean 'Result::ENTITY'?}} |
| 395 |
case LITERAL: // expected-error {{use of undeclared identifier 'LITERAL'; did you mean 'Result::LITERAL'?}} |
| 396 |
case PREDICAT: // expected-error {{use of undeclared identifier 'PREDICAT'; did you mean 'Result::PREDICATE'?}} |
| 397 |
break; |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
class Figure { |
| 402 |
enum ResultType { |
| 403 |
SQUARE, |
| 404 |
TRIANGLE, |
| 405 |
CIRCLE |
| 406 |
}; |
| 407 |
|
| 408 |
public: |
| 409 |
ResultType type(); |
| 410 |
}; |
| 411 |
|
| 412 |
void testAccess() { |
| 413 |
Figure obj; |
| 414 |
switch (obj.type()) { |
| 415 |
case SQUARE: // expected-error-re {{use of undeclared identifier 'SQUARE'{{$}}}} |
| 416 |
case TRIANGLE: // expected-error-re {{use of undeclared identifier 'TRIANGLE'{{$}}}} |
| 417 |
case CIRCE: // expected-error-re {{use of undeclared identifier 'CIRCE'{{$}}}} |
| 418 |
break; |
| 419 |
} |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
long readline(const char *, char *, unsigned long); |
| 424 |
void assign_to_unknown_var() { |
| 425 |
deadline_ = 1; // expected-error-re {{use of undeclared identifier 'deadline_'{{$}}}} |
| 426 |
} |
| 427 |
|
| 428 |
namespace no_ns_before_dot { |
| 429 |
namespace re2 {} |
| 430 |
void test() { |
| 431 |
req.set_check(false); // expected-error-re {{use of undeclared identifier 'req'{{$}}}} |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
namespace PR17394 { |
| 436 |
class A { |
| 437 |
protected: |
| 438 |
long zzzzzzzzzz; |
| 439 |
}; |
| 440 |
class B : private A {}; |
| 441 |
B zzzzzzzzzy<>; // expected-error {{template specialization requires 'template<>'}} expected-error {{no variable template matches specialization}} |
| 442 |
} |
| 443 |
|
| 444 |
namespace correct_fields_in_member_funcs { |
| 445 |
struct S { |
| 446 |
int my_member; // expected-note {{'my_member' declared here}} |
| 447 |
void f() { my_menber = 1; } // expected-error {{use of undeclared identifier 'my_menber'; did you mean 'my_member'?}} |
| 448 |
}; |
| 449 |
} |
| 450 |
|
| 451 |
namespace PR17019 { |
| 452 |
template<class F> |
| 453 |
struct evil { |
| 454 |
evil(F de) { // expected-note {{'de' declared here}} |
| 455 |
de_; // expected-error {{use of undeclared identifier 'de_'; did you mean 'de'?}} \ |
| 456 |
// expected-warning {{expression result unused}} |
| 457 |
} |
| 458 |
~evil() { |
| 459 |
de_->bar() // expected-error {{use of undeclared identifier 'de_'}} |
| 460 |
} |
| 461 |
}; |
| 462 |
|
| 463 |
void meow() { |
| 464 |
evil<int> Q(0); // expected-note {{in instantiation of member function}} |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
namespace fix_class_name_qualifier { |
| 469 |
class MessageHeaders {}; |
| 470 |
class MessageUtils { |
| 471 |
public: |
| 472 |
static void ParseMessageHeaders(int, int); // expected-note {{'MessageUtils::ParseMessageHeaders' declared here}} |
| 473 |
}; |
| 474 |
|
| 475 |
void test() { |
| 476 |
// No, we didn't mean to call MessageHeaders::MessageHeaders. |
| 477 |
MessageHeaders::ParseMessageHeaders(5, 4); // expected-error {{no member named 'ParseMessageHeaders' in 'fix_class_name_qualifier::MessageHeaders'; did you mean 'MessageUtils::ParseMessageHeaders'?}} |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
namespace PR18213 { // expected-note {{'PR18213' declared here}} |
| 482 |
struct WrapperInfo { |
| 483 |
int i; |
| 484 |
}; |
| 485 |
|
| 486 |
template <typename T> struct Wrappable { |
| 487 |
static WrapperInfo kWrapperInfo; |
| 488 |
}; |
| 489 |
|
| 490 |
// Note the space before "::PR18213" is intended and needed, as it highlights |
| 491 |
// the actual typo, which is the leading "::". |
| 492 |
// TODO: Suggest removing the "::" from "::PR18213" (the right correction) |
| 493 |
// instead of incorrectly suggesting dropping "PR18213::WrapperInfo::". |
| 494 |
template <> |
| 495 |
PR18213::WrapperInfo ::PR18213::Wrappable<int>::kWrapperInfo = { 0 }; // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \ |
| 496 |
// expected-error {{a type specifier is required for all declarations}} |
| 497 |
} |
| 498 |
|
| 499 |
namespace PR18651 { |
| 500 |
struct { |
| 501 |
int x; |
| 502 |
} a, b; |
| 503 |
|
| 504 |
int y = x; // expected-error-re {{use of undeclared identifier 'x'{{$}}}} |
| 505 |
} |
| 506 |
|
| 507 |
namespace PR18685 { |
| 508 |
template <class C, int I, int J> |
| 509 |
class SetVector { |
| 510 |
public: |
| 511 |
SetVector() {} |
| 512 |
}; |
| 513 |
|
| 514 |
template <class C, int I> |
| 515 |
class SmallSetVector : public SetVector<C, I, 8> {}; |
| 516 |
|
| 517 |
class foo {}; |
| 518 |
SmallSetVector<foo*, 2> fooSet; |
| 519 |
} |
| 520 |
|
| 521 |
PR18685::BitVector Map; // expected-error-re {{no type named 'BitVector' in namespace 'PR18685'{{$}}}} |
| 522 |
|
| 523 |
namespace shadowed_template { |
| 524 |
template <typename T> class Fizbin {}; // expected-note {{'::shadowed_template::Fizbin' declared here}} |
| 525 |
class Baz { |
| 526 |
int Fizbin; |
| 527 |
Fizbin<int> qux; // expected-error {{no template named 'Fizbin'; did you mean '::shadowed_template::Fizbin'?}} |
| 528 |
}; |
| 529 |
} |
| 530 |
|
| 531 |
namespace no_correct_template_id_to_non_template { |
| 532 |
struct Frobnatz {}; // expected-note {{declared here}} |
| 533 |
Frobnats fn; // expected-error {{unknown type name 'Frobnats'; did you mean 'Frobnatz'?}} |
| 534 |
Frobnats<int> fni; // expected-error-re {{no template named 'Frobnats'{{$}}}} |
| 535 |
} |
| 536 |
|
| 537 |
namespace PR18852 { |
| 538 |
void func() { |
| 539 |
struct foo { |
| 540 |
void barberry() {} |
| 541 |
}; |
| 542 |
barberry(); // expected-error-re {{use of undeclared identifier 'barberry'{{$}}}} |
| 543 |
} |
| 544 |
|
| 545 |
class Thread { |
| 546 |
public: |
| 547 |
void Start(); |
| 548 |
static void Stop(); // expected-note {{'Thread::Stop' declared here}} |
| 549 |
}; |
| 550 |
|
| 551 |
class Manager { |
| 552 |
public: |
| 553 |
void Start(int); // expected-note {{'Start' declared here}} |
| 554 |
void Stop(int); // expected-note {{'Stop' declared here}} |
| 555 |
}; |
| 556 |
|
| 557 |
void test(Manager *m) { |
| 558 |
// Don't suggest Thread::Start as a correction just because it has the same |
| 559 |
// (unqualified) name and accepts the right number of args; this is a method |
| 560 |
// call on an object in an unrelated class. |
| 561 |
m->Start(); // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}} |
| 562 |
m->Stop(); // expected-error-re {{too few arguments to function call, expected 1, have 0{{$}}}} |
| 563 |
Stop(); // expected-error {{use of undeclared identifier 'Stop'; did you mean 'Thread::Stop'?}} |
| 564 |
} |
| 565 |
|
| 566 |
} |
| 567 |
|
| 568 |
namespace std { |
| 569 |
class bernoulli_distribution { |
| 570 |
public: |
| 571 |
double p() const; |
| 572 |
}; |
| 573 |
} |
| 574 |
void test() { |
| 575 |
// Make sure that typo correction doesn't suggest changing 'p' to |
| 576 |
// 'std::bernoulli_distribution::p' as that is most likely wrong. |
| 577 |
if (p) // expected-error-re {{use of undeclared identifier 'p'{{$}}}} |
| 578 |
return; |
| 579 |
} |
| 580 |
|
| 581 |
namespace PR19681 { |
| 582 |
struct TypoA {}; |
| 583 |
struct TypoB { |
| 584 |
void test(); |
| 585 |
private: |
| 586 |
template<typename T> void private_memfn(T); // expected-note{{declared here}} |
| 587 |
}; |
| 588 |
void TypoB::test() { |
| 589 |
// FIXME: should suggest 'PR19681::TypoB::private_memfn' instead of '::PR19681::TypoB::private_memfn' |
| 590 |
(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'?}} |
| 591 |
} |
| 592 |
} |
| 593 |
|
| 594 |
namespace testWantFunctionLikeCasts { |
| 595 |
long test(bool a) { |
| 596 |
if (a) |
| 597 |
return struc(5.7); // expected-error-re {{use of undeclared identifier 'struc'{{$}}}} |
| 598 |
else |
| 599 |
return lon(8.0); // expected-error {{use of undeclared identifier 'lon'; did you mean 'long'?}} |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
namespace testCXXDeclarationSpecifierParsing { |
| 604 |
namespace test { |
| 605 |
struct SomeSettings {}; // expected-note {{'test::SomeSettings' declared here}} |
| 606 |
} |
| 607 |
class Test {}; |
| 608 |
int bar() { |
| 609 |
Test::SomeSettings some_settings; // expected-error {{no type named 'SomeSettings' in 'testCXXDeclarationSpecifierParsing::Test'; did you mean 'test::SomeSettings'?}} |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
namespace testIncludeTypeInTemplateArgument { |
| 614 |
template <typename T, typename U> |
| 615 |
void foo(T t = {}, U = {}); // expected-note {{candidate template ignored}} |
| 616 |
|
| 617 |
class AddObservation {}; // expected-note {{declared here}} |
| 618 |
int bar1() { |
| 619 |
// should resolve to a class. |
| 620 |
foo<AddObservationFn, int>(); // expected-error {{unknown type name 'AddObservationFn'; did you mean 'AddObservation'?}} |
| 621 |
|
| 622 |
// should not resolve to a class. |
| 623 |
foo(AddObservationFn, 1); // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$}}}} |
| 624 |
int a = AddObservationFn, b; // expected-error-re {{use of undeclared identifier 'AddObservationFn'{{$}}}} |
| 625 |
|
| 626 |
int AddObservation; // expected-note 3{{declared here}} |
| 627 |
// should resolve to a local variable. |
| 628 |
foo(AddObservationFn, 1); // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} |
| 629 |
int c = AddObservationFn, d; // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} |
| 630 |
|
| 631 |
// FIXME: would be nice to not resolve to a variable. |
| 632 |
foo<AddObservationFn, int>(); // expected-error {{use of undeclared identifier 'AddObservationFn'; did you mean}} \ |
| 633 |
expected-error {{no matching function for call}} |
| 634 |
} |
| 635 |
} // namespace testIncludeTypeInTemplateArgument |
| 636 |
|
| 637 |
namespace testNoCrashOnNullNNSTypoCorrection { |
| 638 |
int AddObservation(); |
| 639 |
template <typename T, typename... Args> |
| 640 |
class UsingImpl {}; |
| 641 |
class AddObservation { // expected-note {{declared here}} |
| 642 |
using Using = |
| 643 |
// should resolve to a class. |
| 644 |
UsingImpl<AddObservationFn, const int>; // expected-error {{unknown type name 'AddObservationFn'; did you mean}} |
| 645 |
}; |
| 646 |
} // namespace testNoCrashOnNullNNSTypoCorrection |
| 647 |
|
| 648 |
namespace testNonStaticMemberHandling { |
| 649 |
struct Foo { |
| 650 |
bool usesMetadata; |
| 651 |
}; |
| 652 |
int test(Foo f) { |
| 653 |
if (UsesMetadata) // expected-error-re {{use of undeclared identifier 'UsesMetadata'{{$}}}} |
| 654 |
return 5; |
| 655 |
if (f.UsesMetadata) // expected-error {{no member named 'UsesMetadata' in 'testNonStaticMemberHandling::Foo'}} |
| 656 |
return 11; |
| 657 |
return 0; |
| 658 |
} |
| 659 |
}; |
| 660 |
|
| 661 |
namespace testMemberExprDeclarationNameInfo { |
| 662 |
// The AST should only have the corrected name with no mention of 'data_'. |
| 663 |
void f(int); |
| 664 |
struct S { |
| 665 |
int data; // expected-note 2{{'data' declared here}} |
| 666 |
void m_fn1() { |
| 667 |
data_ // expected-error {{use of undeclared identifier 'data_'}} |
| 668 |
[] = // expected-error {{expected expression}} |
| 669 |
f(data_); // expected-error {{use of undeclared identifier 'data_'}} |
| 670 |
} |
| 671 |
}; |
| 672 |
} |
| 673 |
|
| 674 |
namespace testArraySubscriptIndex { |
| 675 |
struct S { |
| 676 |
int data; // expected-note {{'data' declared here}} |
| 677 |
void m_fn1() { |
| 678 |
(+)[data_]; // expected-error{{expected expression}} expected-error {{use of undeclared identifier 'data_'; did you mean 'data'}} |
| 679 |
} |
| 680 |
}; |
| 681 |
} |
| 682 |
|
| 683 |
namespace crash_has_include { |
| 684 |
int has_include(int); // expected-note {{'has_include' declared here}} |
| 685 |
// expected-error@+1 {{'__has_include' must be used within a preprocessing directive}} |
| 686 |
int foo = __has_include(42); // expected-error {{use of undeclared identifier '__has_include'; did you mean 'has_include'?}} |
| 687 |
} |
| 688 |
|
| 689 |
namespace PR24781_using_crash { |
| 690 |
namespace A { |
| 691 |
namespace B { |
| 692 |
class Foofoo {}; // expected-note {{'A::B::Foofoo' declared here}} |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
namespace C { |
| 697 |
namespace D { |
| 698 |
class Bar : public A::B::Foofoo {}; |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
using C::D::Foofoo; // expected-error {{no member named 'Foofoo' in namespace 'PR24781_using_crash::C::D'; did you mean 'A::B::Foofoo'?}} |
| 703 |
} |
| 704 |
|
| 705 |
int d = ? L : d; // expected-error {{expected expression}} expected-error {{undeclared identifier}} |
| 706 |
|
| 707 |
struct B0 { |
| 708 |
int : 0 | |
| 709 |
(struct B0)e; // expected-error {{use of undeclared identifier}} |
| 710 |
}; |
| 711 |
|
| 712 |
namespace { |
| 713 |
struct a0is0 {}; |
| 714 |
struct b0is0 {}; |
| 715 |
int g() { |
| 716 |
0 [ |
| 717 |
sizeof(c0is0)]; // expected-error {{use of undeclared identifier}} |
| 718 |
}; |
| 719 |
} |
| 720 |
|
| 721 |
namespace avoidRedundantRedefinitionErrors { |
| 722 |
class Class { |
| 723 |
void function(int pid); // expected-note {{'function' declared here}} |
| 724 |
}; |
| 725 |
|
| 726 |
void Class::function2(int pid) { // expected-error {{out-of-line definition of 'function2' does not match any declaration in 'avoidRedundantRedefinitionErrors::Class'; did you mean 'function'?}} |
| 727 |
} |
| 728 |
|
| 729 |
// Expected no redefinition error here. |
| 730 |
void Class::function(int pid) { // expected-note {{previous definition is here}} |
| 731 |
} |
| 732 |
|
| 733 |
void Class::function(int pid) { // expected-error {{redefinition of 'function'}} |
| 734 |
} |
| 735 |
|
| 736 |
namespace ns { |
| 737 |
void create_test(); // expected-note {{'create_test' declared here}} |
| 738 |
} |
| 739 |
|
| 740 |
void ns::create_test2() { // expected-error {{out-of-line definition of 'create_test2' does not match any declaration in namespace 'avoidRedundantRedefinitionErrors::ns'; did you mean 'create_test'?}} |
| 741 |
} |
| 742 |
|
| 743 |
// Expected no redefinition error here. |
| 744 |
void ns::create_test() { |
| 745 |
} |
| 746 |
} |
| 747 |
|
| 748 |
namespace PR46487 { |
| 749 |
bool g_var_bool; // expected-note {{here}} |
| 750 |
const char g_volatile_char = 5; // expected-note {{here}} |
| 751 |
// FIXME: We shouldn't suggest a typo-correction to 'g_var_bool' here, |
| 752 |
// because it doesn't make the expression valid. |
| 753 |
// expected-error@+2 {{did you mean 'g_var_bool'}} |
| 754 |
// expected-error@+1 {{assigning to 'bool' from incompatible type 'void'}} |
| 755 |
enum : typename decltype((g_var_long = throw))::a { |
| 756 |
b = g_volatile_uchar // expected-error {{did you mean 'g_volatile_char'}} |
| 757 |
}; |
| 758 |
} |
| 759 |
|
| 760 |
namespace PR47272 |
| 761 |
{ |
| 762 |
|
| 763 |
namespace Views { |
| 764 |
int Take(); // expected-note{{'Views::Take' declared here}} |
| 765 |
} |
| 766 |
|
| 767 |
namespace [[deprecated("use Views instead")]] View { |
| 768 |
using Views::Take; |
| 769 |
} |
| 770 |
|
| 771 |
namespace [[deprecated]] A { // expected-note{{'A' has been explicitly marked deprecated here}} |
| 772 |
int pr47272; |
| 773 |
} |
| 774 |
|
| 775 |
namespace B { |
| 776 |
using A::pr47272; // expected-note{{'B::pr47272' declared here}} expected-warning{{'A' is deprecated}} |
| 777 |
} |
| 778 |
|
| 779 |
namespace [[deprecated]] C { |
| 780 |
using A::pr47272; |
| 781 |
} |
| 782 |
|
| 783 |
void function() { |
| 784 |
int x = ::Take(); // expected-error{{no member named 'Take' in the global namespace; did you mean 'Views::Take'?}} |
| 785 |
int y = ::pr47272; // expected-error{{no member named 'pr47272' in the global namespace; did you mean 'B::pr47272'?}} |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
|