From b1a95e0b150a9423dd4ad8b9fdc97426cfa7764f Mon Sep 17 00:00:00 2001
From: Mark Mitchell <mark@codesourcery.com>
Date: Thu, 29 Jan 2004 02:21:51 +0000
Subject: [PATCH] re PR c++/13791 (ICE in layout_type with packed types)

	PR c++/13791
	* typeck.c (merge_types): Do not merge attributes into
	TYPENAME_TYPEs.

2004-01-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/13791
	* g++.dg/ext/attrib12.C: New test.

From-SVN: r76837
---
 gcc/cp/ChangeLog                    |  4 ++++
 gcc/cp/typeck.c                     |  6 ++++++
 gcc/testsuite/ChangeLog             |  3 +++
 gcc/testsuite/g++.dg/ext/attrib12.C | 16 ++++++++++++++++
 4 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/ext/attrib12.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 73451be58df1..873a79fd1aa6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
 2004-01-28  Mark Mitchell  <mark@codesourcery.com>
 
+	PR c++/13791
+	* typeck.c (merge_types): Do not merge attributes into
+	TYPENAME_TYPEs.
+
 	PR c++/13736
 	* parser.c (cp_parser_direct_declarator): Do not prevent
 	backtracking inside a parenthesized declarator.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index b2dfe647a6bd..137cedede721 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -714,6 +714,12 @@ merge_types (tree t1, tree t2)
 	break;
       }
 
+    case TYPENAME_TYPE:
+      /* There is no need to merge attributes into a TYPENAME_TYPE.
+	 When the type is instantiated it will have whatever
+	 attributes result from the instantiation.  */
+      return t1;
+
     default:;
     }
   return build_type_attribute_variant (t1, attributes);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4a498e761ab1..d5cbccb74424 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2004-01-28  Mark Mitchell  <mark@codesourcery.com>
 
+	PR c++/13791
+	* g++.dg/ext/attrib12.C: New test.
+
 	PR c++/13736
 	* g++.dg/parse/cast2.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/ext/attrib12.C b/gcc/testsuite/g++.dg/ext/attrib12.C
new file mode 100644
index 000000000000..aea93781df89
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib12.C
@@ -0,0 +1,16 @@
+// PR c++/13791
+
+template <typename T> struct O {
+  struct __attribute__((packed)) I {
+    int i;
+    char c;
+  };
+
+  I* foo();
+};
+
+template <typename T>
+typename O<T>::I*
+O<T>::foo() { return 0; }
+
+template class O<int>;
-- 
GitLab