aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/DeclCXX.h18
-rw-r--r--lib/Sema/SemaDecl.cpp5
-rw-r--r--lib/Sema/SemaDeclCXX.cpp11
-rw-r--r--lib/Sema/SemaExpr.cpp7
4 files changed, 13 insertions, 28 deletions
diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h
index 9ca1823f38..2db0ca2274 100644
--- a/include/clang/AST/DeclCXX.h
+++ b/include/clang/AST/DeclCXX.h
@@ -642,18 +642,13 @@ class CXXConstructorDecl : public CXXMethodDecl {
/// @c !Implicit && ImplicitlyDefined.
bool ImplicitlyDefined : 1;
- /// ImplicitMustBeDefined - Implicit constructor was used to create an
- /// object of its class type. It must be defined.
- bool ImplicitMustBeDefined : 1;
-
/// FIXME: Add support for base and member initializers.
CXXConstructorDecl(CXXRecordDecl *RD, SourceLocation L,
DeclarationName N, QualType T,
bool isExplicit, bool isInline, bool isImplicitlyDeclared)
: CXXMethodDecl(CXXConstructor, RD, L, N, T, false, isInline),
- Explicit(isExplicit), ImplicitlyDefined(false),
- ImplicitMustBeDefined(false) {
+ Explicit(isExplicit), ImplicitlyDefined(false) {
setImplicit(isImplicitlyDeclared);
}
@@ -683,17 +678,6 @@ public:
"Can only set the implicit-definition flag once the constructor has been defined");
ImplicitlyDefined = ID;
}
-
- /// isImplicitMustBeDefined - Whether a definition must be synthesized for
- /// the implicit constructor.
- bool isImplicitMustBeDefined() const {
- return isImplicit() && ImplicitMustBeDefined;
- }
-
- /// setImplicitMustBeDefined - constructor must be implicitly defined.
- void setImplicitMustBeDefined() {
- ImplicitMustBeDefined = true;
- }
/// isDefaultConstructor - Whether this constructor is a default
/// constructor (C++ [class.ctor]p5), which can be used to
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 06fd1a1736..eba1d58d60 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2733,12 +2733,9 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl) {
IK_Default);
if (!Constructor)
Var->setInvalidDecl();
- else {
+ else
if (!RD->hasTrivialConstructor())
InitializeVarWithConstructor(Var, Constructor, InitType, 0, 0);
- // Check for valid construction.
- DefineImplicitDefaultConstructor(Var->getLocation(), Constructor);
- }
}
}
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 6d740eb5b7..6e17450093 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -1843,7 +1843,7 @@ Sema::DeclPtrTy Sema::ActOnNamespaceAliasDef(Scope *S,
void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
CXXConstructorDecl *Constructor) {
if (!Constructor->isDefaultConstructor() ||
- !Constructor->isImplicit() || Constructor->isImplicitMustBeDefined())
+ !Constructor->isImplicit() || Constructor->isUsed())
return;
CXXRecordDecl *ClassDecl
@@ -1862,7 +1862,7 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
if (CXXConstructorDecl *BaseCtor =
BaseClassDecl->getDefaultConstructor(Context)) {
if (BaseCtor->isImplicit())
- BaseCtor->setImplicitMustBeDefined();
+ BaseCtor->setUsed();
}
else {
Diag(CurrentLocation, diag::err_defining_default_ctor)
@@ -1887,7 +1887,7 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
if (CXXConstructorDecl *FieldCtor =
FieldClassDecl->getDefaultConstructor(Context)) {
if (FieldCtor->isImplicit())
- FieldCtor->setImplicitMustBeDefined();
+ FieldCtor->setUsed();
}
else {
Diag(CurrentLocation, diag::err_defining_default_ctor)
@@ -1912,7 +1912,7 @@ void Sema::DefineImplicitDefaultConstructor(SourceLocation CurrentLocation,
}
}
if (!err)
- Constructor->setImplicitMustBeDefined();
+ Constructor->setUsed();
}
void Sema::InitializeVarWithConstructor(VarDecl *VD,
@@ -1990,9 +1990,6 @@ void Sema::AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
VDecl->setCXXDirectInitializer(true);
InitializeVarWithConstructor(VDecl, Constructor, DeclInitType,
(Expr**)Exprs.release(), NumExprs);
- // An implicitly-declared default constructor for a class is implicitly
- // defined when it is used to creat an object of its class type.
- DefineImplicitDefaultConstructor(VDecl->getLocation(), Constructor);
}
return;
}
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 692502bbbe..e989b1f282 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -5461,6 +5461,13 @@ void Sema::MarkDeclarationReferenced(SourceLocation Loc, Decl *D) {
return;
// Note that this declaration has been used.
+ if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(D)) {
+ DefineImplicitDefaultConstructor(Loc, Constructor);
+ // FIXME: set the Used flag if it is determined that ctor is valid.
+ Constructor->setUsed(true);
+ return;
+ }
+
if (FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
// FIXME: implicit template instantiation
// FIXME: keep track of references to static functions