aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-10-01 23:51:25 +0000
committerDouglas Gregor <dgregor@apple.com>2009-10-01 23:51:25 +0000
commitb2f81cf7f8445e0c65c0428f4fbb0442566916b8 (patch)
tree30b26fa8e325b2b8f254b8bf24c865c4a3603119
parentd789d3d985e28c9404e62157af46dcb7331920e0 (diff)
Make sure to free the explicit template arguments provided for an
explicit instantiation. Also, tighten up reference-count checking to help catch these issues earlier. Fixes PR5069. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83225 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Stmt.h5
-rw-r--r--lib/Sema/SemaTemplate.cpp1
-rw-r--r--test/SemaTemplate/explicit-instantiation.cpp4
3 files changed, 9 insertions, 1 deletions
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 125279c1ed..411f215e91 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -188,7 +188,10 @@ public:
return this;
}
- StmtClass getStmtClass() const { return (StmtClass)sClass; }
+ StmtClass getStmtClass() const {
+ assert(RefCount >= 1 && "Referencing already-destroyed statement!");
+ return (StmtClass)sClass;
+ }
const char *getStmtClassName() const;
/// SourceLocation tokens are not useful in isolation - they are low level
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index c7ce032594..d12ec9318a 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -3414,6 +3414,7 @@ Sema::DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
TemplateId->getTemplateArgLocations(),
TemplateArgs);
HasExplicitTemplateArgs = true;
+ TemplateArgsPtr.release();
}
// C++ [temp.explicit]p1:
diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp
index 07994f97d3..b9a4ad282b 100644
--- a/test/SemaTemplate/explicit-instantiation.cpp
+++ b/test/SemaTemplate/explicit-instantiation.cpp
@@ -69,3 +69,7 @@ template void print_type<int>(float*); // expected-error{{does not refer}}
void print_type(double*);
template void print_type<double>(double*);
+
+// PR5069
+template<int I> void foo0 (int (&)[I + 1]) { }
+template void foo0<2> (int (&)[3]);