From 3a36343b88599312cb335248b90f3f6ed47370dd Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 22 Jun 2009 17:30:33 +0000 Subject: [PATCH] Remove ImplicitMustBeDefined, use universal 'Used' flag instead. Do the implicit default ctor checking in MarkDeclarationReferenced. llvm-svn: 73888 --- clang/include/clang/AST/DeclCXX.h | 18 +----------------- clang/lib/Sema/SemaDecl.cpp | 5 +---- clang/lib/Sema/SemaDeclCXX.cpp | 11 ++++------- clang/lib/Sema/SemaExpr.cpp | 7 +++++++ 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 9ca1823f3822..2db0ca2274d0 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/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/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 06fd1a17362a..eba1d58d6024 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 6d740eb5b7ec..6e1745009387 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/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/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 692502bbbe81..e989b1f282fd 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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(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(D)) { // FIXME: implicit template instantiation // FIXME: keep track of references to static functions