forked from OSchip/llvm-project
When performing a user-defined conversion via a constructor, be sure
to check whether the constructor is accessible. Fixes <rdar://problem/10202900>. llvm-svn: 141588
This commit is contained in:
parent
8f34b6999c
commit
c7a3107baf
|
@ -2057,18 +2057,22 @@ static ExprResult BuildCXXCastArgument(Sema &S,
|
|||
switch (Kind) {
|
||||
default: llvm_unreachable("Unhandled cast kind!");
|
||||
case CK_ConstructorConversion: {
|
||||
CXXConstructorDecl *Constructor = cast<CXXConstructorDecl>(Method);
|
||||
ASTOwningVector<Expr*> ConstructorArgs(S);
|
||||
|
||||
if (S.CompleteConstructorCall(cast<CXXConstructorDecl>(Method),
|
||||
if (S.CompleteConstructorCall(Constructor,
|
||||
MultiExprArg(&From, 1),
|
||||
CastLoc, ConstructorArgs))
|
||||
return ExprError();
|
||||
|
||||
ExprResult Result =
|
||||
S.BuildCXXConstructExpr(CastLoc, Ty, cast<CXXConstructorDecl>(Method),
|
||||
move_arg(ConstructorArgs), HadMultipleCandidates,
|
||||
/*ZeroInit*/ false, CXXConstructExpr::CK_Complete,
|
||||
SourceRange());
|
||||
S.CheckConstructorAccess(CastLoc, Constructor, Constructor->getAccess(),
|
||||
S.PDiag(diag::err_access_ctor));
|
||||
|
||||
ExprResult Result
|
||||
= S.BuildCXXConstructExpr(CastLoc, Ty, cast<CXXConstructorDecl>(Method),
|
||||
move_arg(ConstructorArgs),
|
||||
HadMultipleCandidates, /*ZeroInit*/ false,
|
||||
CXXConstructExpr::CK_Complete, SourceRange());
|
||||
if (Result.isInvalid())
|
||||
return ExprError();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
// PR5775
|
||||
class Twine {
|
||||
public:
|
||||
Twine(const char *Str) { }
|
||||
};
|
||||
|
||||
|
|
|
@ -82,3 +82,18 @@ float &f(...);
|
|||
void g(X2 b) {
|
||||
int &ir = f(b); // expected-error{{no viable constructor copying parameter of type 'X1'}}
|
||||
}
|
||||
|
||||
namespace rdar10202900 {
|
||||
class A {
|
||||
public:
|
||||
A();
|
||||
|
||||
private:
|
||||
A(int i); // expected-note{{declared private here}}
|
||||
};
|
||||
|
||||
void testA(A a) {
|
||||
int b = 10;
|
||||
a = b; // expected-error{{calling a private constructor of class 'rdar10202900::A'}}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue