From 21a6617c34c4c15183b5edf4d7df910395aad0b4 Mon Sep 17 00:00:00 2001 From: Kaelyn Uhrain Date: Wed, 5 Feb 2014 18:57:51 +0000 Subject: [PATCH] Don't consider records with a NULL identifier as a name for typo correction. Because in C++, "anonymous" doesn't mean "nameless" for records. In other words, RecordDecl::isAnonymousStructOrUnion only returns true if the record lacks a name *and* is not used as the type in an object's declaration. llvm-svn: 200868 --- clang/lib/Sema/SemaLookup.cpp | 2 +- clang/test/SemaCXX/typo-correction-pt2.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 39dd555aeae7..8a5c0a5ba7eb 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -4216,7 +4216,7 @@ TypoCorrection Sema::CorrectTypo(const DeclarationNameInfo &TypoName, if (CXXRecordDecl *CD = (*TI)->getAsCXXRecordDecl()) { CD = CD->getCanonicalDecl(); if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() && - !CD->isUnion() && + !CD->isUnion() && CD->getIdentifier() && (CD->isBeingDefined() || CD->isCompleteDefinition())) Namespaces.AddNameSpecifier(CD); } diff --git a/clang/test/SemaCXX/typo-correction-pt2.cpp b/clang/test/SemaCXX/typo-correction-pt2.cpp index 789510049011..65d961085a8c 100644 --- a/clang/test/SemaCXX/typo-correction-pt2.cpp +++ b/clang/test/SemaCXX/typo-correction-pt2.cpp @@ -199,3 +199,11 @@ template <> PR18213::WrapperInfo ::PR18213::Wrappable::kWrapperInfo = { 0 }; // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \ // expected-error {{C++ requires a type specifier for all declarations}} } + +namespace PR18651 { +struct { + int x; +} a, b; + +int y = x; // expected-error-re {{use of undeclared identifier 'x'{{$}}}} +}