From fb6b29821a2adbc2aa3ed4c117f7bcfa3ad3df35 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 1 Apr 2015 19:31:06 +0000 Subject: [PATCH] Minor simplification: do typo-correction before handling inheriting constructors, instead of having the typo-correction code also dispatch to the inheriting constructor special case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233833 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 44 ++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index aa1bfac7e0..7b2848bf60 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -8091,15 +8091,7 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS, if (RequireCompleteDeclContext(SS, LookupContext)) return BuildInvalid(); - // The normal rules do not apply to inheriting constructor declarations. - if (NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName) { - UsingDecl *UD = BuildValid(); - CheckInheritingConstructorUsingDecl(UD); - return UD; - } - - // Otherwise, look up the target name. - + // Look up the target name. LookupResult R(*this, NameInfo, LookupOrdinaryName); // Unlike most lookups, we don't always want to hide tag @@ -8118,8 +8110,12 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS, LookupQualifiedName(R, LookupContext); - // Try to correct typos if possible. - if (R.empty()) { + // Try to correct typos if possible. If constructor name lookup finds no + // results, that means the named class has no explicit constructors, and we + // suppressed declaring implicit ones (probably because it's dependent or + // invalid). + if (R.empty() && + NameInfo.getName().getNameKind() != DeclarationName::CXXConstructorName) { if (TypoCorrection Corrected = CorrectTypo( R.getLookupNameInfo(), R.getLookupKind(), S, &SS, llvm::make_unique( @@ -8149,16 +8145,12 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS, NameInfo.setName(Context.DeclarationNames.getCXXConstructorName( Context.getCanonicalType(Context.getRecordType(RD)))); NameInfo.setNamedTypeInfo(nullptr); - - // Build it and process it as an inheriting constructor. - UsingDecl *UD = BuildValid(); - CheckInheritingConstructorUsingDecl(UD); - return UD; + for (auto *Ctor : LookupConstructors(RD)) + R.addDecl(Ctor); + } else { + // FIXME: Pick up all the declarations if we found an overloaded function. + R.addDecl(ND); } - - // FIXME: Pick up all the declarations if we found an overloaded function. - R.setLookupName(Corrected.getCorrection()); - R.addDecl(ND); } else { Diag(IdentLoc, diag::err_no_member) << NameInfo.getName() << LookupContext << SS.getRange(); @@ -8198,6 +8190,18 @@ NamedDecl *Sema::BuildUsingDeclaration(Scope *S, AccessSpecifier AS, } UsingDecl *UD = BuildValid(); + + // The normal rules do not apply to inheriting constructor declarations. + if (NameInfo.getName().getNameKind() == DeclarationName::CXXConstructorName) { + // Suppress access diagnostics; the access check is instead performed at the + // point of use for an inheriting constructor. + R.suppressDiagnostics(); + CheckInheritingConstructorUsingDecl(UD); + return UD; + } + + // Otherwise, look up the target name. + for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) { UsingShadowDecl *PrevDecl = nullptr; if (!CheckUsingShadowDecl(UD, *I, Previous, PrevDecl)) -- 2.40.0