Patchwork [C++] PR 53491

login
register
mail settings
Submitter Paolo Carlini
Date May 26, 2012, 3:31 p.m.
Message ID <4FC0F738.2070108@oracle.com>
Download mbox | patch
Permalink /patch/161492/
State New
Headers show

Comments

Paolo Carlini - May 26, 2012, 3:31 p.m.
On 05/26/2012 04:21 PM, Jason Merrill wrote:
> I think I would rather fix stabilize_expr to handle void arguments 
> properly: basically just stick the whole argument in *initp and return 
> void_zero_node.
Ok. Like this it works, if I understand your suggestion.

Thanks,
Paolo.

////////////////////
/cp
2012-05-26  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53491
	* tree.c (stabilize_expr): Handle exp of void type.

/testsuite
2012-05-26  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53491
	* g++.dg/parse/crash60.C: New.
Jason Merrill - May 26, 2012, 5:58 p.m.
On 05/26/2012 11:31 AM, Paolo Carlini wrote:
> Ok. Like this it works, if I understand your suggestion.

Yep, that's what I had in mind. But let's put it after the 
!TREE_SIDE_EFFECTS case.  OK with that change.

Jason

Patch

Index: testsuite/g++.dg/parse/crash60.C
===================================================================
--- testsuite/g++.dg/parse/crash60.C	(revision 0)
+++ testsuite/g++.dg/parse/crash60.C	(revision 0)
@@ -0,0 +1,14 @@ 
+// PR c++/53491
+
+struct M
+{
+  void pop();
+};
+
+void foo()
+{
+  int result = 0;
+  M m;
+
+  result += m.pop();  // { dg-error "invalid operands|in evaluation" }
+}
Index: cp/tree.c
===================================================================
--- cp/tree.c	(revision 187915)
+++ cp/tree.c	(working copy)
@@ -3279,7 +3279,12 @@  stabilize_expr (tree exp, tree* initp)
 {
   tree init_expr;
 
-  if (!TREE_SIDE_EFFECTS (exp))
+  if (VOID_TYPE_P (TREE_TYPE (exp)))
+    {
+      *initp = exp;
+      return void_zero_node;
+    }
+  else if (!TREE_SIDE_EFFECTS (exp))
     init_expr = NULL_TREE;
   /* There are no expressions with REFERENCE_TYPE, but there can be call
      arguments with such a type; just treat it as a pointer.  */