From 8b739b9f705739d597985e6bab670579d43c30ed Mon Sep 17 00:00:00 2001
From: mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Sun, 17 Apr 2005 03:43:01 +0000
Subject: [PATCH] 	PR c++/21025 	* typeck.c
 (cxx_sizeof_or_alignof_type): Check whether the type to 	which
 sizeof/alignof is dependent, rather than just whether we are 
 processing_template_decl.

	PR c++/21025
	* g++.dg/template/sizeof9.C: New test.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98252 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/cp/ChangeLog                        | 7 +++++++
 gcc/cp/typeck.c                         | 2 +-
 gcc/testsuite/ChangeLog                 | 7 +++++++
 gcc/testsuite/g++.dg/template/sizeof9.C | 6 ++++++
 4 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/sizeof9.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 739f9936bce3..81e75b9148d4 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2005-04-16  Mark Mitchell  <mark@codesourcery.com>
+
+	PR c++/21025
+	* typeck.c (cxx_sizeof_or_alignof_type): Check whether the type to
+	which sizeof/alignof is dependent, rather than just whether we are
+	processing_template_decl.
+	
 2005-04-17  Kazu Hirata  <kazu@cs.umass.edu>
 
 	* cp-tree.h (LOOKUP_GLOBAL): Remove.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 272dc86891fc..6ccffe1ceeb6 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -1221,7 +1221,7 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
   if (type == error_mark_node)
     return error_mark_node;
   
-  if (processing_template_decl)
+  if (dependent_type_p (type))
     {
       value = build_min (op, size_type_node, type);
       TREE_READONLY (value) = 1;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9b5b6e1b1199..f9b274dcca6d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2005-04-16  Mark Mitchell  <mark@codesourcery.com>
+
+	PR c++/21025
+	* typeck.c (cxx_sizeof_or_alignof_type): Check whether the type to
+	which sizeof/alignof is dependent, rather than just whether we are
+	processing_template_decl.
+	
 2005-04-15  Thomas Koenig  <Thomas.Koenig@online.de>
 
 	* gfortran.fortran-torture/execute/intrinsic_spread.f90:
diff --git a/gcc/testsuite/g++.dg/template/sizeof9.C b/gcc/testsuite/g++.dg/template/sizeof9.C
new file mode 100644
index 000000000000..8d9ec95ae1f0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/sizeof9.C
@@ -0,0 +1,6 @@
+// PR c++/21025
+
+template<int N> struct X { char x[N]; };
+template<typename T> X<1 + sizeof(T) - sizeof(T)> F(T const &);
+template<int N> struct S { int d() { F(1); } };
+
-- 
GitLab