diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -13890,10 +13890,6 @@ return cast(Ctor); DeclarationNameInfo NameInfo(Name, UsingLoc); - TypeSourceInfo *TInfo = - Context.getTrivialTypeSourceInfo(BaseCtor->getType(), UsingLoc); - FunctionProtoTypeLoc ProtoLoc = - TInfo->getTypeLoc().IgnoreParens().castAs(); // Check the inherited constructor is valid and find the list of base classes // from which it was inherited. @@ -13905,8 +13901,9 @@ false, BaseCtor, &ICI); CXXConstructorDecl *DerivedCtor = CXXConstructorDecl::Create( - Context, Derived, UsingLoc, NameInfo, TInfo->getType(), TInfo, - BaseCtor->getExplicitSpecifier(), getCurFPFeatures().isFPConstrained(), + Context, Derived, UsingLoc, NameInfo, BaseCtor->getType(), + /*TInfo=*/nullptr, BaseCtor->getExplicitSpecifier(), + getCurFPFeatures().isFPConstrained(), /*isInline=*/true, /*isImplicitlyDeclared=*/true, Constexpr ? BaseCtor->getConstexprKind() : ConstexprSpecKind::Unspecified, @@ -13916,7 +13913,8 @@ DerivedCtor->setInvalidDecl(); // Build an unevaluated exception specification for this fake constructor. - const FunctionProtoType *FPT = TInfo->getType()->castAs(); + const FunctionProtoType *FPT = + BaseCtor->getType()->castAs(); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); EPI.ExceptionSpec.Type = EST_Unevaluated; EPI.ExceptionSpec.SourceDecl = DerivedCtor; @@ -13926,18 +13924,15 @@ // Build the parameter declarations. SmallVector ParamDecls; for (unsigned I = 0, N = FPT->getNumParams(); I != N; ++I) { - TypeSourceInfo *TInfo = - Context.getTrivialTypeSourceInfo(FPT->getParamType(I), UsingLoc); ParmVarDecl *PD = ParmVarDecl::Create( Context, DerivedCtor, UsingLoc, UsingLoc, /*IdentifierInfo=*/nullptr, - FPT->getParamType(I), TInfo, SC_None, /*DefArg=*/nullptr); + FPT->getParamType(I), /*TInfo=*/nullptr, SC_None, /*DefArg=*/nullptr); PD->setScopeInfo(0, I); PD->setImplicit(); // Ensure attributes are propagated onto parameters (this matters for // format, pass_object_size, ...). mergeDeclAttributes(PD, BaseCtor->getParamDecl(I)); ParamDecls.push_back(PD); - ProtoLoc.setParam(I, PD); } // Set up the new constructor. diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -2129,6 +2129,21 @@ notMatches(Code, typeAliasTemplateDecl(hasName("typeAliasDecl")))); } +TEST_P(ASTMatchersTest, TypeLocTest_DoesNotBindToSyntheticParams) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(notMatches( + R"cpp( + struct Base { Base(int); }; + struct Derived : Base { using Base::Base; }; + Derived d(42); // force constructor to exist + )cpp", + cxxRecordDecl(hasAnyName("Derived"), + hasDescendant(typeLoc( + anyOf(loc(functionType()), loc(asString("int")))))))); +} + TEST_P(ASTMatchersTest, QualifiedTypeLocTest_BindsToConstIntVarDecl) { EXPECT_TRUE(matches("const int x = 0;", qualifiedTypeLoc(loc(asString("const int")))));