Patchwork [C++] Fix ICE in lvalue_kind (PR c++/45894)

login
register
mail settings
Submitter Jakub Jelinek
Date Nov. 8, 2010, 10:12 p.m.
Message ID <20101108221217.GT29412@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/70467/
State New
Headers show

Comments

Jakub Jelinek - Nov. 8, 2010, 10:12 p.m.
Hi!

As the testcase shows, in some cases -Wsequence-point warning code
calls lvalue_p e.g. on baselink with template_id_expr (where the
latter has no type and thus lvalue_kind segfaults).

Fixed by robustifying lvalue_kind, bootstrapped/regtested on x86_64-linux
and i686-linux, ok for trunk?

2010-11-05  Jakub Jelinek  <jakub@redhat.com>

	PR c++/45894
	* tree.c (lvalue_kind): Don't crash if ref has NULL type.

	* g++.dg/warn/Wsequence-point-2.C: New test.


	Jakub
Jason Merrill - Nov. 9, 2010, 3:57 a.m.
OK.

Jason

Patch

--- gcc/cp/tree.c.jj	2010-11-03 16:58:26.000000000 +0100
+++ gcc/cp/tree.c	2010-11-05 13:45:53.000000000 +0100
@@ -67,7 +67,8 @@  lvalue_kind (const_tree ref)
 	  == REFERENCE_TYPE)
     return lvalue_kind (TREE_OPERAND (ref, 0));
 
-  if (TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
+  if (TREE_TYPE (ref)
+      && TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE)
     {
       /* unnamed rvalue references are rvalues */
       if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref))
--- gcc/testsuite/g++.dg/warn/Wsequence-point-2.C.jj	2010-11-08 18:09:07.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/Wsequence-point-2.C	2010-11-08 18:08:04.000000000 +0100
@@ -0,0 +1,28 @@ 
+// PR c++/45894
+// { dg-do compile }
+// { dg-options "-std=c++0x -Wsequence-point" }
+
+struct F
+{
+  template <typename = int>
+  void bar ();
+};
+template <typename = int>
+struct V
+{
+  V (const V &) { F::bar <>; }
+};
+struct C
+{
+  V <> v;
+};
+struct B
+{
+  C f ();
+};
+struct A
+{
+  C c;
+  B b;
+  A () : c (b.f ()) { }
+};