[clang] d5d8c52 - PR48545: Access check the inherited constructor, not the inheriting
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 9 13:28:14 PST 2021
Author: Richard Smith
Date: 2021-02-09T13:27:55-08:00
New Revision: d5d8c529abe65ce55c24b0333842bb31746a8bf8
URL: https://github.com/llvm/llvm-project/commit/d5d8c529abe65ce55c24b0333842bb31746a8bf8
DIFF: https://github.com/llvm/llvm-project/commit/d5d8c529abe65ce55c24b0333842bb31746a8bf8.diff
LOG: 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.
Added:
Modified:
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/cxx11-inheriting-ctors.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 640755cec222..c1a2be744853 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -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;
diff --git a/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp b/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp
index 5be428401fa0..39582660984b 100644
--- a/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp
+++ b/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp
@@ -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);
+ }
+}
More information about the cfe-commits
mailing list