Reinstate the fix for PR7556. A silly use of isTrivial() was
suppressing copies of objects with trivial copy constructors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107857 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h
index 6da32ba..aacb000 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -822,12 +822,8 @@
///
/// This expression type represents a C++ "functional" cast
/// (C++[expr.type.conv]) with N != 1 arguments that invokes a
-/// constructor to build a temporary object. If N == 0 but no
-/// constructor will be called (because the functional cast is
-/// performing a value-initialized an object whose class type has no
-/// user-declared constructors), CXXZeroInitValueExpr will represent
-/// the functional cast. Finally, with N == 1 arguments the functional
-/// cast expression will be represented by CXXFunctionalCastExpr.
+/// constructor to build a temporary object. With N == 1 arguments the
+/// functional cast expression will be represented by CXXFunctionalCastExpr.
/// Example:
/// @code
/// struct X { X(int, float); }
@@ -861,22 +857,21 @@
static bool classof(const CXXTemporaryObjectExpr *) { return true; }
};
-/// CXXZeroInitValueExpr - [C++ 5.2.3p2]
+/// CXXScalarValueInitExpr - [C++ 5.2.3p2]
/// Expression "T()" which creates a value-initialized rvalue of type
-/// T, which is either a non-class type or a class type without any
-/// user-defined constructors.
+/// T, which is a non-class type.
///
-class CXXZeroInitValueExpr : public Expr {
+class CXXScalarValueInitExpr : public Expr {
SourceLocation TyBeginLoc;
SourceLocation RParenLoc;
public:
- CXXZeroInitValueExpr(QualType ty, SourceLocation tyBeginLoc,
+ CXXScalarValueInitExpr(QualType ty, SourceLocation tyBeginLoc,
SourceLocation rParenLoc ) :
- Expr(CXXZeroInitValueExprClass, ty, false, false),
+ Expr(CXXScalarValueInitExprClass, ty, false, false),
TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
- explicit CXXZeroInitValueExpr(EmptyShell Shell)
- : Expr(CXXZeroInitValueExprClass, Shell) { }
+ explicit CXXScalarValueInitExpr(EmptyShell Shell)
+ : Expr(CXXScalarValueInitExprClass, Shell) { }
SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
SourceLocation getRParenLoc() const { return RParenLoc; }
@@ -895,9 +890,9 @@
}
static bool classof(const Stmt *T) {
- return T->getStmtClass() == CXXZeroInitValueExprClass;
+ return T->getStmtClass() == CXXScalarValueInitExprClass;
}
- static bool classof(const CXXZeroInitValueExpr *) { return true; }
+ static bool classof(const CXXScalarValueInitExpr *) { return true; }
// Iterators
virtual child_iterator child_begin();
diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h
index bf88aa0..f734c9a 100644
--- a/include/clang/AST/RecursiveASTVisitor.h
+++ b/include/clang/AST/RecursiveASTVisitor.h
@@ -1545,7 +1545,7 @@
return true;
}
-DEF_TRAVERSE_STMT(CXXZeroInitValueExpr, {
+DEF_TRAVERSE_STMT(CXXScalarValueInitExpr, {
// This is called for code like 'return MyClass()' where MyClass
// has no user-defined constructor. It's also called for 'return
// int()'. We recurse on type MyClass/int.
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index f88a0ae..0883eab 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -509,6 +509,9 @@
def err_access_dtor_temp :
Error<"temporary of type %0 has %select{private|protected}1 destructor">,
NoSFINAE;
+def err_access_dtor_exception :
+ Error<"exception object of type %0 has %select{private|protected}1 "
+ "destructor">, NoSFINAE;
def err_access_dtor_field :
Error<"field of type %1 has %select{private|protected}2 destructor">,
NoSFINAE;
diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td
index bfdac74..a2f6973 100644
--- a/include/clang/Basic/StmtNodes.td
+++ b/include/clang/Basic/StmtNodes.td
@@ -95,7 +95,7 @@
def CXXThisExpr : DStmt<Expr>;
def CXXThrowExpr : DStmt<Expr>;
def CXXDefaultArgExpr : DStmt<Expr>;
-def CXXZeroInitValueExpr : DStmt<Expr>;
+def CXXScalarValueInitExpr : DStmt<Expr>;
def CXXNewExpr : DStmt<Expr>;
def CXXDeleteExpr : DStmt<Expr>;
def CXXPseudoDestructorExpr : DStmt<Expr>;
diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h
index f3fb053..4da9604 100644
--- a/include/clang/Frontend/PCHBitCodes.h
+++ b/include/clang/Frontend/PCHBitCodes.h
@@ -778,7 +778,7 @@
EXPR_CXX_DEFAULT_ARG, // CXXDefaultArgExpr
EXPR_CXX_BIND_TEMPORARY, // CXXBindTemporaryExpr
//
- EXPR_CXX_ZERO_INIT_VALUE, // CXXZeroInitValueExpr
+ EXPR_CXX_SCALAR_VALUE_INIT, // CXXScalarValueInitExpr
EXPR_CXX_NEW, // CXXNewExpr
EXPR_CXX_DELETE, // CXXDeleteExpr
EXPR_CXX_PSEUDO_DESTRUCTOR, // CXXPseudoDestructorExpr
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 4d950c0..d41051f 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -261,7 +261,7 @@
#include "clang/AST/TypeNodes.def"
fprintf(stderr, "Total bytes = %d\n", int(TotalBytes));
-
+
// Implicit special member functions.
fprintf(stderr, " %u/%u implicit default constructors created\n",
NumImplicitDefaultConstructorsDeclared,
@@ -282,6 +282,9 @@
fprintf(stderr, "\n");
ExternalSource->PrintStats();
}
+
+ if (!FreeMemory)
+ BumpAlloc.PrintStats();
}
diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp
index 08d8ae4..c3c5ccc 100644
--- a/lib/AST/ExprCXX.cpp
+++ b/lib/AST/ExprCXX.cpp
@@ -74,11 +74,11 @@
return child_iterator();
}
-// CXXZeroInitValueExpr
-Stmt::child_iterator CXXZeroInitValueExpr::child_begin() {
+// CXXScalarValueInitExpr
+Stmt::child_iterator CXXScalarValueInitExpr::child_begin() {
return child_iterator();
}
-Stmt::child_iterator CXXZeroInitValueExpr::child_end() {
+Stmt::child_iterator CXXScalarValueInitExpr::child_end() {
return child_iterator();
}
diff --git a/lib/AST/ExprClassification.cpp b/lib/AST/ExprClassification.cpp
index 4629500..60ac347 100644
--- a/lib/AST/ExprClassification.cpp
+++ b/lib/AST/ExprClassification.cpp
@@ -205,7 +205,7 @@
// Some C++ expressions are always class temporaries.
case Expr::CXXConstructExprClass:
case Expr::CXXTemporaryObjectExprClass:
- case Expr::CXXZeroInitValueExprClass:
+ case Expr::CXXScalarValueInitExprClass:
return Cl::CL_ClassTemporary;
// Everything we haven't handled is a prvalue.
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 5dae4d4..a963182 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -938,7 +938,7 @@
return Success(0, E);
}
- bool VisitCXXZeroInitValueExpr(const CXXZeroInitValueExpr *E) {
+ bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E) {
return Success(0, E);
}
@@ -1756,7 +1756,7 @@
bool VisitBinaryOperator(const BinaryOperator *E);
bool VisitFloatingLiteral(const FloatingLiteral *E);
bool VisitCastExpr(CastExpr *E);
- bool VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
+ bool VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
bool VisitConditionalOperator(ConditionalOperator *E);
bool VisitChooseExpr(const ChooseExpr *E)
@@ -1952,7 +1952,7 @@
return false;
}
-bool FloatExprEvaluator::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+bool FloatExprEvaluator::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Result = APFloat::getZero(Info.Ctx.getFloatTypeSemantics(E->getType()));
return true;
}
@@ -2410,7 +2410,7 @@
case Expr::IntegerLiteralClass:
case Expr::CharacterLiteralClass:
case Expr::CXXBoolLiteralExprClass:
- case Expr::CXXZeroInitValueExprClass:
+ case Expr::CXXScalarValueInitExprClass:
case Expr::TypesCompatibleExprClass:
case Expr::UnaryTypeTraitExprClass:
return NoDiag();
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index 964106f..7043c35 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -1086,7 +1086,7 @@
OS << ")";
}
-void StmtPrinter::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *Node) {
+void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) {
OS << Node->getType().getAsString(Policy) << "()";
}
diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp
index 4b17e52..2c69186 100644
--- a/lib/AST/StmtProfile.cpp
+++ b/lib/AST/StmtProfile.cpp
@@ -721,7 +721,7 @@
VisitCXXConstructExpr(S);
}
-void StmtProfiler::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *S) {
+void StmtProfiler::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *S) {
VisitExpr(S);
}
diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp
index d4a410e..4652a4c 100644
--- a/lib/Checker/GRExprEngine.cpp
+++ b/lib/Checker/GRExprEngine.cpp
@@ -655,7 +655,7 @@
case Stmt::CXXTryStmtClass:
case Stmt::CXXTypeidExprClass:
case Stmt::CXXUnresolvedConstructExprClass:
- case Stmt::CXXZeroInitValueExprClass:
+ case Stmt::CXXScalarValueInitExprClass:
case Stmt::DependentScopeDeclRefExprClass:
case Stmt::UnaryTypeTraitExprClass:
case Stmt::UnresolvedLookupExprClass:
@@ -962,7 +962,7 @@
// C++ stuff we don't support yet.
case Stmt::CXXExprWithTemporariesClass:
case Stmt::CXXMemberCallExprClass:
- case Stmt::CXXZeroInitValueExprClass: {
+ case Stmt::CXXScalarValueInitExprClass: {
SaveAndRestore<bool> OldSink(Builder->BuildSinks);
Builder->BuildSinks = true;
MakeNode(Dst, Ex, Pred, GetState(Pred));
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 3621dbb..0426a60 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -544,8 +544,8 @@
return EmitCXXBindTemporaryLValue(cast<CXXBindTemporaryExpr>(E));
case Expr::CXXExprWithTemporariesClass:
return EmitCXXExprWithTemporariesLValue(cast<CXXExprWithTemporaries>(E));
- case Expr::CXXZeroInitValueExprClass:
- return EmitNullInitializationLValue(cast<CXXZeroInitValueExpr>(E));
+ case Expr::CXXScalarValueInitExprClass:
+ return EmitNullInitializationLValue(cast<CXXScalarValueInitExpr>(E));
case Expr::CXXDefaultArgExprClass:
return EmitLValue(cast<CXXDefaultArgExpr>(E)->getExpr());
case Expr::CXXTypeidExprClass:
@@ -1829,7 +1829,7 @@
}
LValue CodeGenFunction::EmitNullInitializationLValue(
- const CXXZeroInitValueExpr *E) {
+ const CXXScalarValueInitExpr *E) {
QualType Ty = E->getType();
LValue LV = LValue::MakeAddr(CreateMemTemp(Ty), MakeQualifiers(Ty));
EmitNullInitialization(LV.getAddress(), Ty);
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index 35b7016..20722f7 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -127,7 +127,7 @@
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
void VisitCXXConstructExpr(const CXXConstructExpr *E);
void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E);
- void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
+ void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
void VisitCXXTypeidExpr(CXXTypeidExpr *E) { EmitAggLoadOfLValue(E); }
void VisitVAArgExpr(VAArgExpr *E);
@@ -557,7 +557,7 @@
CGF.EmitCXXExprWithTemporaries(E, Val, VolatileDest, IsInitializer);
}
-void AggExprEmitter::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+void AggExprEmitter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
llvm::Value *Val = DestPtr;
if (!Val) {
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index f2e6a11..69e5f0e 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -572,6 +572,14 @@
}
if (CXXConstructorDecl *Ctor = E->getConstructor()) {
+ // Per C++ [expr.new]p15, if we have an initializer, then we're performing
+ // direct initialization. C++ [dcl.init]p5 requires that we
+ // zero-initialize storage if there are no user-declared constructors.
+ if (E->hasInitializer() &&
+ !Ctor->getParent()->hasUserDeclaredConstructor() &&
+ !Ctor->getParent()->isEmpty())
+ CGF.EmitNullInitialization(NewPtr, E->getAllocatedType());
+
CGF.EmitCXXConstructorCall(Ctor, Ctor_Complete, /*ForVirtualBase=*/false,
NewPtr, E->constructor_arg_begin(),
E->constructor_arg_end());
diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp
index c2e10bf..90b6446 100644
--- a/lib/CodeGen/CGExprComplex.cpp
+++ b/lib/CodeGen/CGExprComplex.cpp
@@ -181,7 +181,7 @@
ComplexPairTy VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) {
return CGF.EmitCXXExprWithTemporaries(E).getComplexVal();
}
- ComplexPairTy VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+ ComplexPairTy VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
assert(E->getType()->isAnyComplexType() && "Expected complex type!");
QualType Elem = E->getType()->getAs<ComplexType>()->getElementType();
llvm::Constant *Null = llvm::Constant::getNullValue(CGF.ConvertType(Elem));
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index 8c120fa..1ebc2c5 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -126,7 +126,7 @@
Value *VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
}
- Value *VisitCXXZeroInitValueExpr(const CXXZeroInitValueExpr *E) {
+ Value *VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E) {
return EmitNullValue(E->getType());
}
Value *VisitGNUNullExpr(const GNUNullExpr *E) {
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 3e4cd3b..26fb882 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -1209,7 +1209,7 @@
LValue EmitCompoundLiteralLValue(const CompoundLiteralExpr *E);
LValue EmitConditionalOperatorLValue(const ConditionalOperator *E);
LValue EmitCastLValue(const CastExpr *E);
- LValue EmitNullInitializationLValue(const CXXZeroInitValueExpr *E);
+ LValue EmitNullInitializationLValue(const CXXScalarValueInitExpr *E);
llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
const ObjCIvarDecl *Ivar);
diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp
index 28641e8..d330eec 100644
--- a/lib/Frontend/PCHReaderStmt.cpp
+++ b/lib/Frontend/PCHReaderStmt.cpp
@@ -132,7 +132,7 @@
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
- void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
+ void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
void VisitCXXNewExpr(CXXNewExpr *E);
void VisitCXXDeleteExpr(CXXDeleteExpr *E);
void VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
@@ -1003,7 +1003,7 @@
E->setSubExpr(Reader.ReadSubExpr());
}
-void PCHStmtReader::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+void PCHStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
VisitExpr(E);
E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
@@ -1574,8 +1574,8 @@
S = new (Context) CXXBindTemporaryExpr(Empty);
break;
- case pch::EXPR_CXX_ZERO_INIT_VALUE:
- S = new (Context) CXXZeroInitValueExpr(Empty);
+ case pch::EXPR_CXX_SCALAR_VALUE_INIT:
+ S = new (Context) CXXScalarValueInitExpr(Empty);
break;
case pch::EXPR_CXX_NEW:
S = new (Context) CXXNewExpr(Empty);
diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp
index 91f9353..00cebf1 100644
--- a/lib/Frontend/PCHWriterStmt.cpp
+++ b/lib/Frontend/PCHWriterStmt.cpp
@@ -132,7 +132,7 @@
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E);
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E);
- void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E);
+ void VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E);
void VisitCXXNewExpr(CXXNewExpr *E);
void VisitCXXDeleteExpr(CXXDeleteExpr *E);
void VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E);
@@ -1007,11 +1007,11 @@
Code = pch::EXPR_CXX_BIND_TEMPORARY;
}
-void PCHStmtWriter::VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+void PCHStmtWriter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
VisitExpr(E);
Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
Writer.AddSourceLocation(E->getRParenLoc(), Record);
- Code = pch::EXPR_CXX_ZERO_INIT_VALUE;
+ Code = pch::EXPR_CXX_SCALAR_VALUE_INIT;
}
void PCHStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) {
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 021b4af..180b591 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -460,7 +460,7 @@
MarkDeclarationReferenced(E->getExprLoc(), Destructor);
CheckDestructorAccess(E->getExprLoc(), Destructor,
- PDiag(diag::err_access_dtor_temp) << Ty);
+ PDiag(diag::err_access_dtor_exception) << Ty);
return false;
}
@@ -546,27 +546,19 @@
RParenLoc));
}
- if (const RecordType *RT = Ty->getAs<RecordType>()) {
- CXXRecordDecl *Record = cast<CXXRecordDecl>(RT->getDecl());
+ if (Ty->isRecordType()) {
+ InitializedEntity Entity = InitializedEntity::InitializeTemporary(Ty);
+ InitializationKind Kind
+ = NumExprs ? InitializationKind::CreateDirect(TypeRange.getBegin(),
+ LParenLoc, RParenLoc)
+ : InitializationKind::CreateValue(TypeRange.getBegin(),
+ LParenLoc, RParenLoc);
+ InitializationSequence InitSeq(*this, Entity, Kind, Exprs, NumExprs);
+ OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind,
+ move(exprs));
- if (NumExprs > 1 || !Record->hasTrivialConstructor() ||
- !Record->hasTrivialDestructor()) {
- InitializedEntity Entity = InitializedEntity::InitializeTemporary(Ty);
- InitializationKind Kind
- = NumExprs ? InitializationKind::CreateDirect(TypeRange.getBegin(),
- LParenLoc, RParenLoc)
- : InitializationKind::CreateValue(TypeRange.getBegin(),
- LParenLoc, RParenLoc);
- InitializationSequence InitSeq(*this, Entity, Kind, Exprs, NumExprs);
- OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind,
- move(exprs));
-
- // FIXME: Improve AST representation?
- return move(Result);
- }
-
- // Fall through to value-initialize an object of class type that
- // doesn't have a user-declared default constructor.
+ // FIXME: Improve AST representation?
+ return move(Result);
}
// C++ [expr.type.conv]p1:
@@ -585,7 +577,7 @@
// rvalue of the specified type, which is value-initialized.
//
exprs.release();
- return Owned(new (Context) CXXZeroInitValueExpr(Ty, TyBeginLoc, RParenLoc));
+ return Owned(new (Context) CXXScalarValueInitExpr(Ty, TyBeginLoc, RParenLoc));
}
@@ -1992,7 +1984,7 @@
BasePath);
}
- if (isa<CXXZeroInitValueExpr>(rex->IgnoreParens())) {
+ if (isa<CXXScalarValueInitExpr>(rex->IgnoreParens())) {
// Diagnose use of pointer-to-member type which when used as
// the functional cast in a pointer-to-member expression.
Diag(Loc, diag::err_pointer_to_member_type) << isIndirect;
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index 536222c..5571c1b 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -2772,8 +2772,7 @@
// zero-initialized and, if T’s implicitly-declared default
// constructor is non-trivial, that constructor is called.
if ((ClassDecl->getTagKind() == TTK_Class ||
- ClassDecl->getTagKind() == TTK_Struct) &&
- !ClassDecl->hasTrivialConstructor()) {
+ ClassDecl->getTagKind() == TTK_Struct)) {
Sequence.AddZeroInitializationStep(Entity.getType());
return TryConstructorInitialization(S, Entity, Kind, 0, 0, T, Sequence);
}
@@ -3838,7 +3837,7 @@
} else if (Kind.getKind() == InitializationKind::IK_Value &&
S.getLangOptions().CPlusPlus &&
!Kind.isImplicitValueInit()) {
- CurInit = S.Owned(new (S.Context) CXXZeroInitValueExpr(Step->Type,
+ CurInit = S.Owned(new (S.Context) CXXScalarValueInitExpr(Step->Type,
Kind.getRange().getBegin(),
Kind.getRange().getEnd()));
} else {
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 1abcf20..9c8f48b 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -92,12 +92,6 @@
if (const CXXExprWithTemporaries *Temps = dyn_cast<CXXExprWithTemporaries>(E))
E = Temps->getSubExpr();
- if (const CXXZeroInitValueExpr *Zero = dyn_cast<CXXZeroInitValueExpr>(E)) {
- if (const RecordType *RecordT = Zero->getType()->getAs<RecordType>())
- if (CXXRecordDecl *RecordD = dyn_cast<CXXRecordDecl>(RecordT->getDecl()))
- if (!RecordD->hasTrivialDestructor())
- return;
- }
if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
if (E->getType()->isVoidType())
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index b2a4059..95e304e 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -1577,7 +1577,7 @@
///
/// By default, performs semantic analysis to build the new expression.
/// Subclasses may override this routine to provide different behavior.
- OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
+ OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
SourceLocation LParenLoc,
QualType T,
SourceLocation RParenLoc) {
@@ -5219,7 +5219,7 @@
template<typename Derived>
Sema::OwningExprResult
-TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
+TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
QualType T = getDerived().TransformType(E->getType());
@@ -5230,10 +5230,10 @@
T == E->getType())
return SemaRef.Owned(E->Retain());
- return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
- /*FIXME:*/E->getTypeBeginLoc(),
- T,
- E->getRParenLoc());
+ return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
+ /*FIXME:*/E->getTypeBeginLoc(),
+ T,
+ E->getRParenLoc());
}
template<typename Derived>
diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp
index 552c52f..90a1449 100644
--- a/test/CXX/class.access/p4.cpp
+++ b/test/CXX/class.access/p4.cpp
@@ -423,6 +423,7 @@
// PR7281
namespace test16 {
- class A { ~A(); }; // expected-note {{declared private here}}
- void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}}
+ class A { ~A(); }; // expected-note 2{{declared private here}}
+ void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}} \
+ // expected-error{{exception object of type 'test16::A' has private destructor}}
}
diff --git a/test/CodeGenCXX/default-arg-temps.cpp b/test/CodeGenCXX/default-arg-temps.cpp
index e4a0677..c441985 100644
--- a/test/CodeGenCXX/default-arg-temps.cpp
+++ b/test/CodeGenCXX/default-arg-temps.cpp
@@ -44,7 +44,6 @@
// CHECK: define void @_Z1hv()
void h() {
// CHECK: call void @llvm.memset.p0i8.i64(
- // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(
obj o = obj();
}
diff --git a/test/CodeGenCXX/temporaries.cpp b/test/CodeGenCXX/temporaries.cpp
index eb543cb..9a397ab 100644
--- a/test/CodeGenCXX/temporaries.cpp
+++ b/test/CodeGenCXX/temporaries.cpp
@@ -320,3 +320,21 @@
f(1);
}
}
+
+namespace PR7556 {
+ struct A { ~A(); };
+ struct B { int i; ~B(); };
+ struct C { int C::*pm; ~C(); };
+ // CHECK: define void @_ZN6PR75563fooEv()
+ void foo() {
+ // CHECK: call void @_ZN6PR75561AD1Ev
+ A();
+ // CHECK: call void @llvm.memset.p0i8.i64
+ // CHECK: call void @_ZN6PR75561BD1Ev
+ B();
+ // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
+ // CHECK: call void @_ZN6PR75561CD1Ev
+ C();
+ // CHECK-NEXT: ret void
+ }
+}
diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp
index 5ef7e70..6992cdc 100644
--- a/test/SemaCXX/warn-unused-variables.cpp
+++ b/test/SemaCXX/warn-unused-variables.cpp
@@ -26,7 +26,7 @@
};
void test() {
- A(); // expected-warning{{expression result unused}}
+ A();
B(17);
C();
}
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 0f9f79d..be3623f 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -174,7 +174,7 @@
case Stmt::CXXThisExprClass:
case Stmt::CXXThrowExprClass:
case Stmt::CXXDefaultArgExprClass:
- case Stmt::CXXZeroInitValueExprClass:
+ case Stmt::CXXScalarValueInitExprClass:
case Stmt::CXXNewExprClass:
case Stmt::CXXDeleteExprClass:
case Stmt::CXXPseudoDestructorExprClass: