summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-04-16 23:50:50 +0000
committerAnders Carlsson <andersca@mac.com>2009-04-16 23:50:50 +0000
commite6840d84dfc8b08a493f096b393ebe7f6faa72f2 (patch)
treef0dd60479cde9cc684ec17696435f75c65ffb5a8
parent302279ed06c52314713906264aa2630cb973066c (diff)
downloadbcm5719-llvm-e6840d84dfc8b08a493f096b393ebe7f6faa72f2.tar.gz
bcm5719-llvm-e6840d84dfc8b08a493f096b393ebe7f6faa72f2.zip
If a class has a non-trivial constructor that doesn't take any arguments, we will now make an implicit CXXTemporaryObjectExpr. So
struct S { S(); }; void f() { S s; } 's' here will implicitly be declared as. S s = S(); llvm-svn: 69326
-rw-r--r--clang/lib/Sema/Sema.h7
-rw-r--r--clang/lib/Sema/SemaDecl.cpp6
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp24
3 files changed, 26 insertions, 11 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index fd708516f4e..ef20a6a3302 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -1418,6 +1418,13 @@ public:
SourceLocation *CommaLocs,
SourceLocation RParenLoc);
+ /// InitializeVarWithConstructor - Creates an implicit
+ /// CXXTemporaryObjectExpr and sets it as the passed in VarDecl initializer.
+ void InitializeVarWithConstructor(VarDecl *VD,
+ CXXConstructorDecl *Constructor,
+ QualType DeclInitType,
+ Expr **Exprs, unsigned NumExprs);
+
/// InitializationKind - Represents which kind of C++ initialization
/// [dcl.init] a routine is to perform.
enum InitializationKind {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 94b3b76a3ba..a2b565beb60 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2552,7 +2552,9 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl) {
if (const ArrayType *Array = Context.getAsArrayType(Type))
InitType = Array->getElementType();
if (!Var->hasExternalStorage() && InitType->isRecordType()) {
- const CXXConstructorDecl *Constructor = 0;
+ CXXRecordDecl *RD =
+ cast<CXXRecordDecl>(InitType->getAsRecordType()->getDecl());
+ CXXConstructorDecl *Constructor = 0;
if (!RequireCompleteType(Var->getLocation(), InitType,
diag::err_invalid_incomplete_type_use))
Constructor
@@ -2564,6 +2566,8 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl) {
IK_Default);
if (!Constructor)
Var->setInvalidDecl();
+ else if (!RD->hasTrivialConstructor())
+ InitializeVarWithConstructor(Var, Constructor, InitType, 0, 0);
}
}
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 8e2302ed64f..e3195a9b281 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1764,6 +1764,18 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
return DeclPtrTy::make(AliasDecl);
}
+void Sema::InitializeVarWithConstructor(VarDecl *VD,
+ CXXConstructorDecl *Constructor,
+ QualType DeclInitType,
+ Expr **Exprs, unsigned NumExprs) {
+ Expr *Temp =
+ new (Context) CXXTemporaryObjectExpr(Constructor, DeclInitType,
+ SourceLocation(),
+ Exprs, NumExprs,
+ SourceLocation());
+ VD->setInit(Temp);
+}
+
/// AddCXXDirectInitializerToDecl - This action is called immediately after
/// ActOnDeclarator, when a C++ direct initializer is present.
/// e.g: "int x(1);"
@@ -1827,17 +1839,9 @@ void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
if (!Constructor)
RealDecl->setInvalidDecl();
else {
- // Let clients know that initialization was done with a direct
- // initializer.
VDecl->setCXXDirectInitializer(true);
-
- Expr *Temp =
- new (Context) CXXTemporaryObjectExpr(Constructor, DeclInitType,
- SourceLocation(),
- (Expr**)Exprs.release(),
- NumExprs,
- SourceLocation());
- VDecl->setInit(Temp);
+ InitializeVarWithConstructor(VDecl, Constructor, DeclInitType,
+ (Expr**)Exprs.release(), NumExprs);
}
return;
}
OpenPOWER on IntegriCloud