[cfe-commits] r97568 - in /cfe/trunk: lib/Sema/SemaInit.cpp lib/Sema/TreeTransform.h test/SemaTemplate/instantiate-init.cpp
Douglas Gregor
dgregor at apple.com
Tue Mar 2 09:18:33 PST 2010
Author: dgregor
Date: Tue Mar 2 11:18:33 2010
New Revision: 97568
URL: http://llvm.org/viewvc/llvm-project?rev=97568&view=rev
Log:
Use CXXTemporaryObjectExpr for explicitly-constructed temporaries. We
used to do this, but it got lost when we switched functional-style
cast syntax over to using the new initialization code. Fixes PR6457.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaTemplate/instantiate-init.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=97568&r1=97567&r2=97568&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Tue Mar 2 11:18:33 2010
@@ -3439,10 +3439,25 @@
return S.ExprError();
// Build the an expression that constructs a temporary.
- CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
- Constructor,
- move_arg(ConstructorArgs),
- ConstructorInitRequiresZeroInit,
+ if (Entity.getKind() == InitializedEntity::EK_Temporary &&
+ (Kind.getKind() == InitializationKind::IK_Direct ||
+ Kind.getKind() == InitializationKind::IK_Value)) {
+ // An explicitly-constructed temporary, e.g., X(1, 2).
+ unsigned NumExprs = ConstructorArgs.size();
+ Expr **Exprs = (Expr **)ConstructorArgs.take();
+ S.MarkDeclarationReferenced(Kind.getLocation(), Constructor);
+ CurInit = S.Owned(new (S.Context) CXXTemporaryObjectExpr(S.Context,
+ Constructor,
+ Entity.getType(),
+ Kind.getLocation(),
+ Exprs,
+ NumExprs,
+ Kind.getParenRange().getEnd()));
+ } else
+ CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType(),
+ Constructor,
+ move_arg(ConstructorArgs),
+ ConstructorInitRequiresZeroInit,
Entity.getKind() == InitializedEntity::EK_Base);
if (CurInit.isInvalid())
return S.ExprError();
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=97568&r1=97567&r2=97568&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Mar 2 11:18:33 2010
@@ -5051,6 +5051,11 @@
for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
ArgEnd = E->arg_end();
Arg != ArgEnd; ++Arg) {
+ if (getDerived().DropCallArgument(*Arg)) {
+ ArgumentChanged = true;
+ break;
+ }
+
OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
if (TransArg.isInvalid())
return SemaRef.ExprError();
@@ -5062,8 +5067,11 @@
if (!getDerived().AlwaysRebuild() &&
T == E->getType() &&
Constructor == E->getConstructor() &&
- !ArgumentChanged)
+ !ArgumentChanged) {
+ // FIXME: Instantiation-specific
+ SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
return SemaRef.Owned(E->Retain());
+ }
// FIXME: Bogus location information
SourceLocation CommaLoc;
Modified: cfe/trunk/test/SemaTemplate/instantiate-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-init.cpp?rev=97568&r1=97567&r2=97568&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-init.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-init.cpp Tue Mar 2 11:18:33 2010
@@ -26,3 +26,14 @@
f1(x0, ip, dp); // expected-note{{instantiation}}
}
+namespace PR6457 {
+ template <typename T> struct X { explicit X(T* p = 0) { }; };
+ template <typename T> struct Y { Y(int, const T& x); };
+ struct A { };
+ template <typename T>
+ struct B {
+ B() : y(0, X<A>()) { }
+ Y<X<A> > y;
+ };
+ B<int> b;
+}
More information about the cfe-commits
mailing list