This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix PR c++/33601: canonical types and OFFSET_TYPE


This patch fixes PR c++/33601, which is a canonical types failure due
to mishandling of TYPE_CANONICAL in build_offset_type when the base
type of the OFFSET_TYPE has cv-qualifiers. The OFFSET_TYPE itself
drops those cv-qualifiers, but canonical types weren't doing the same
thing. This bug probably should have been P2, because it had the
potential to affect quite a bit of C++ code... oh well.

Tested i686-pc-linux-gnu and committed as obvious.

  - Doug

2007-10-26  Douglas Gregor  <doug.gregor@gmail.com>

	PR c++/33601
	* tree.c (build_offset_type): Build canonical type based on the
	TYPE_MAIN_VARIANT of the base type.

2007-10-26  Douglas Gregor  <doug.gregor@gmail.com>

	* g++.dg/other/pr33601.C: New.
Index: tree.c
===================================================================
--- tree.c	(revision 129655)
+++ tree.c	(working copy)
@@ -5949,10 +5949,10 @@ build_offset_type (tree basetype, tree t
       if (TYPE_STRUCTURAL_EQUALITY_P (basetype)
 	  || TYPE_STRUCTURAL_EQUALITY_P (type))
 	SET_TYPE_STRUCTURAL_EQUALITY (t);
-      else if (TYPE_CANONICAL (basetype) != basetype
+      else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) != basetype
 	       || TYPE_CANONICAL (type) != type)
 	TYPE_CANONICAL (t) 
-	  = build_offset_type (TYPE_CANONICAL (basetype), 
+	  = build_offset_type (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)),
 			       TYPE_CANONICAL (type));
     }
 
Index: testsuite/g++.dg/other/pr33601.C
===================================================================
--- testsuite/g++.dg/other/pr33601.C	(revision 0)
+++ testsuite/g++.dg/other/pr33601.C	(revision 0)
@@ -0,0 +1,8 @@
+struct A
+{
+  int membervar;
+};
+
+typedef const A type;
+
+int type::* getmemberptr() { return &type::membervar; }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]