[cfe-commits] r100029 - in /cfe/trunk: lib/Sema/TreeTransform.h test/SemaTemplate/instantiate-expr-4.cpp
Chandler Carruth
chandlerc at gmail.com
Wed Mar 31 11:34:59 PDT 2010
Author: chandlerc
Date: Wed Mar 31 13:34:58 2010
New Revision: 100029
URL: http://llvm.org/viewvc/llvm-project?rev=100029&view=rev
Log:
Re-bind non-dependent CXXTemporaryObjectExpr nodes as temporaries when
instantiating a template, which ensures the destructor is called. This fixes
PR6671.
Modified:
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=100029&r1=100028&r2=100029&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Mar 31 13:34:58 2010
@@ -5134,7 +5134,7 @@
!ArgumentChanged) {
// FIXME: Instantiation-specific
SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
- return SemaRef.Owned(E->Retain());
+ return SemaRef.MaybeBindToTemporary(E->Retain());
}
// FIXME: Bogus location information
Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp?rev=100029&r1=100028&r2=100029&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp Wed Mar 31 13:34:58 2010
@@ -43,6 +43,19 @@
template struct Temporaries0<5, 7>;
+// Ensure that both the constructor and the destructor are instantiated by
+// checking for parse errors from each.
+template<int N> struct BadX {
+ BadX() { int a[-N]; } // expected-error {{array size is negative}}
+ ~BadX() { int a[-N]; } // expected-error {{array size is negative}}
+};
+
+template<int N>
+struct PR6671 {
+ void f() { (void)BadX<1>(); } // expected-note 2 {{instantiation}}
+};
+template struct PR6671<1>;
+
// ---------------------------------------------------------------------
// new/delete expressions
// ---------------------------------------------------------------------
More information about the cfe-commits
mailing list