* [C++ Patch] PR 47969
@ 2011-05-02 10:45 Paolo Carlini
2011-05-02 12:33 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Carlini @ 2011-05-02 10:45 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 1490 bytes --]
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.
/////////////////
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);
[-- Attachment #2: CL_47969 --]
[-- Type: text/plain, Size: 295 bytes --]
/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.
[-- Attachment #3: patch_47969_goto --]
[-- Type: text/plain, Size: 1169 bytes --]
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))
{
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ Patch] PR 47969
2011-05-02 10:45 [C++ Patch] PR 47969 Paolo Carlini
@ 2011-05-02 12:33 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2011-05-02 12:33 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
The goto variant is OK.
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-02 12:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-02 10:45 [C++ Patch] PR 47969 Paolo Carlini
2011-05-02 12:33 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).