[cfe-commits] r141588 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/CodeGenCXX/constructor-convert.cpp test/SemaCXX/user-defined-conversions.cpp
Douglas Gregor
dgregor at apple.com
Mon Oct 10 15:41:00 PDT 2011
Author: dgregor
Date: Mon Oct 10 17:41:00 2011
New Revision: 141588
URL: http://llvm.org/viewvc/llvm-project?rev=141588&view=rev
Log:
When performing a user-defined conversion via a constructor, be sure
to check whether the constructor is accessible. Fixes
<rdar://problem/10202900>.
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CodeGenCXX/constructor-convert.cpp
cfe/trunk/test/SemaCXX/user-defined-conversions.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=141588&r1=141587&r2=141588&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Oct 10 17:41:00 2011
@@ -2057,18 +2057,22 @@
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();
Modified: cfe/trunk/test/CodeGenCXX/constructor-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-convert.cpp?rev=141588&r1=141587&r2=141588&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/constructor-convert.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/constructor-convert.cpp Mon Oct 10 17:41:00 2011
@@ -2,6 +2,7 @@
// PR5775
class Twine {
+public:
Twine(const char *Str) { }
};
Modified: cfe/trunk/test/SemaCXX/user-defined-conversions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/user-defined-conversions.cpp?rev=141588&r1=141587&r2=141588&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/user-defined-conversions.cpp (original)
+++ cfe/trunk/test/SemaCXX/user-defined-conversions.cpp Mon Oct 10 17:41:00 2011
@@ -82,3 +82,18 @@
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'}}
+ }
+}
More information about the cfe-commits
mailing list