Patchwork [C++] PR 47969

login
register
mail settings
Submitter Paolo Carlini
Date May 2, 2011, 10:44 a.m.
Message ID <4DBE8AFE.2060906@oracle.com>
Download mbox | patch
Permalink /patch/93628/
State New
Headers show

Comments

Paolo Carlini - May 2, 2011, 10:44 a.m.
Hi,

we have this simple issue where we ICE because we don't check the return 
value of build_expr_type_conversion for NULL_TREE, at variance with all 
its other uses elsewhere.

The fix seems also simple, we have already logic for emitting an error 
message (or just returning error_mark_node depending on complain) in 
case of non-integral size of the array, only, a bit later. Thus my fix, 
adding a goto. If we don't like that, we could do the below, which just 
duplicated the logic. All in all, barring completely different 
solutions, which I don't see at the moment, the goto seems to me a tad 
better.

Tested x86_64-linux.

Ok for mainline?

Paolo.

/////////////////
/cp
2011-05-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/47969
	* decl.c (compute_array_index_type): Check build_expr_type_conversion
	return value for NULL_TREE.

/testsuite
2011-05-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/47969
	* g++.dg/cpp0x/constexpr-47969.C: New.
Index: testsuite/g++.dg/cpp0x/constexpr-47969.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-47969.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-47969.C	(revision 0)
@@ -0,0 +1,11 @@
+// PR c++/47969
+// { dg-options -std=c++0x }
+
+struct A
+{
+  // constexpr operator int () { return 1; }
+};
+
+constexpr A a = A();
+
+int ar[a]; // { dg-error "has non-integral type" }
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 173242)
+++ cp/decl.c	(working copy)
@@ -7609,6 +7609,8 @@ compute_array_index_type (tree name, tree size, ts
 	      && CLASSTYPE_LITERAL_P (type))
 	    {
 	      size = build_expr_type_conversion (WANT_INT, size, true);
+	      if (!size)
+		goto error;
 	      if (size == error_mark_node)
 		return error_mark_node;
 	      type = TREE_TYPE (size);
@@ -7625,6 +7627,7 @@ compute_array_index_type (tree name, tree size, ts
       if (error_operand_p (size))
 	return error_mark_node;
 
+    error:
       /* The array bound must be an integer type.  */
       if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
 	{
Jason Merrill - May 2, 2011, 12:33 p.m.
The goto variant is OK.

Jason

Patch

Index: cp/decl.c
===================================================================
--- cp/decl.c    (revision 173242)
+++ cp/decl.c    (working copy)
@@ -7609,6 +7609,17 @@  compute_array_index_type (tree name, tree size, ts
&& CLASSTYPE_LITERAL_P (type))
          {
            size = build_expr_type_conversion (WANT_INT, size, true);
+          if (!size)
+        {
+          if (!(complain & tf_error))
+            return error_mark_node;
+          if (name)
+            error ("size of array %qD has non-integral type %qT",
+               name, type);
+          else
+            error ("size of array has non-integral type %qT", type);
+          size = integer_one_node;
+        }
            if (size == error_mark_node)
          return error_mark_node;
            type = TREE_TYPE (size);