PR48545: Access check the inherited constructor, not the inheriting

constructor.

We got this wrong only when forming a CXXTemporaryObjectExpr, which
caused the bug to only appear for certain syntactic forms.
This commit is contained in:
Richard Smith 2021-02-09 13:25:52 -08:00
parent 6962bd68f1
commit d5d8c529ab
2 changed files with 27 additions and 5 deletions

View File

@ -6536,22 +6536,23 @@ PerformConstructorInitialization(Sema &S,
? SourceRange(LBraceLoc, RBraceLoc)
: Kind.getParenOrBraceRange();
CXXConstructorDecl *CalleeDecl = Constructor;
if (auto *Shadow = dyn_cast<ConstructorUsingShadowDecl>(
Step.Function.FoundDecl.getDecl())) {
Constructor = S.findInheritingConstructor(Loc, Constructor, Shadow);
if (S.DiagnoseUseOfDecl(Constructor, Loc))
CalleeDecl = S.findInheritingConstructor(Loc, Constructor, Shadow);
if (S.DiagnoseUseOfDecl(CalleeDecl, Loc))
return ExprError();
}
S.MarkFunctionReferenced(Loc, Constructor);
S.MarkFunctionReferenced(Loc, CalleeDecl);
CurInit = S.CheckForImmediateInvocation(
CXXTemporaryObjectExpr::Create(
S.Context, Constructor,
S.Context, CalleeDecl,
Entity.getType().getNonLValueExprType(S.Context), TSInfo,
ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
IsListInitialization, IsStdInitListInitialization,
ConstructorInitRequiresZeroInit),
Constructor);
CalleeDecl);
} else {
CXXConstructExpr::ConstructionKind ConstructKind =
CXXConstructExpr::CK_Complete;

View File

@ -142,3 +142,24 @@ namespace PR47555 {
};
template void f<int>();
}
namespace PR48545 {
struct B {
void f();
private:
B(int, int = 0);
};
struct D : B { using B::B; };
void B::f() {
D{0};
D{0, 0};
D(0);
D(0, 0);
D u = {0};
D v = {0, 0};
D w{0};
D x{0, 0};
D y(0);
D z(0, 0);
}
}