aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2006-10-16 23:06:35 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2006-10-16 23:06:35 +0000
commitb4c74ba24343fb49967075548248964138920c30 (patch)
treefe96515cf4fc58a4cb9a7524973cd76d7d51ac5d
parent571640241cae16fea53dbca4f31ae493d5706aaf (diff)
downloadgcc-b4c74ba24343fb49967075548248964138920c30.zip
gcc-b4c74ba24343fb49967075548248964138920c30.tar.gz
gcc-b4c74ba24343fb49967075548248964138920c30.tar.bz2
re PR c++/29435 (seg fault with sizeof and templates)
PR c++/29435 * typeck.c (cxx_sizeof_or_alignof_type): Complete non-dependent types when their sizes are required. Refine test for VLAs. PR c++/29435 * g++.dg/template/sizeof11.C: New test. From-SVN: r117799
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/typeck.c11
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/template/sizeof11.C14
4 files changed, 31 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a4403a3..f07426a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2006-10-16 Mark Mitchell <mark@codesourcery.com>
+ PR c++/29435
+ * typeck.c (cxx_sizeof_or_alignof_type): Complete non-dependent
+ types when their sizes are required. Refine test for VLAs.
+
PR c++/28211
* parser.c (cp_parser_template_argument): Don't consider "&var" a
possible constant-expression.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 9f8d5e4..b9ee1f2 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -1242,6 +1242,7 @@ tree
cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
{
tree value;
+ bool dependent_p;
gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
if (type == error_mark_node)
@@ -1256,15 +1257,19 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
value = size_one_node;
}
- if (dependent_type_p (type)
+ dependent_p = dependent_type_p (type);
+ if (!dependent_p)
+ complete_type (type);
+ if (dependent_p
/* VLA types will have a non-constant size. In the body of an
uninstantiated template, we don't need to try to compute the
value, because the sizeof expression is not an integral
constant expression in that case. And, if we do try to
compute the value, we'll likely end up with SAVE_EXPRs, which
the template substitution machinery does not expect to see. */
- || (processing_template_decl &&
- TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
+ || (processing_template_decl
+ && COMPLETE_TYPE_P (type)
+ && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST))
{
value = build_min (op, size_type_node, type);
TREE_READONLY (value) = 1;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5fed58b..9d450e7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2006-10-16 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/29435
+ * g++.dg/template/sizeof11.C: New test.
+
2006-10-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29392
diff --git a/gcc/testsuite/g++.dg/template/sizeof11.C b/gcc/testsuite/g++.dg/template/sizeof11.C
new file mode 100644
index 0000000..7428e0b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/sizeof11.C
@@ -0,0 +1,14 @@
+// PR c++/29435
+
+template < class T > struct A {};
+template < int> void g()
+{
+ sizeof (A < int>);
+}
+
+template < class T > struct B;
+template < int> void f()
+{
+ sizeof (B<int>); // { dg-error "incomplete" }
+}
+