* [C++ Patch] PR 42056
@ 2011-05-26 19:38 Paolo Carlini
2011-05-26 20:23 ` Paolo Carlini
2011-05-27 7:20 ` Jason Merrill
0 siblings, 2 replies; 6+ messages in thread
From: Paolo Carlini @ 2011-05-26 19:38 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 555 bytes --]
Hi,
I have just regtested on x86_64-linux the below patchlet for a simple
accepts-invalid, exploiting type_uses_auto, as suggested by Jason.
We want to do that only when processing a template, because otherwise we
get a duplicate diagnostic, see, eg, auto9.C; also, not returning
error_mark_node unconditionally, means a better diagnostic, without
redundant "array bound is not an integer constant before...". As for the
error message itself, I'm just emitting what we otherwise emit outside
templates...
Ok?
Thanks,
Paolo.
///////////////////
[-- Attachment #2: CL_42056 --]
[-- Type: text/plain, Size: 345 bytes --]
/cp
2011-05-26 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42056
* typeck2.c (build_functional_cast): When processing_template_decl,
check for invalid uses of 'auto'.
/testsuite
2011-05-26 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42056
* testsuite/g++.dg/cpp0x/auto25.C: New.
* testsuite/g++.dg/cpp0x/auto26.C: Likewise.
[-- Attachment #3: patch_42056 --]
[-- Type: text/plain, Size: 1266 bytes --]
Index: testsuite/g++.dg/cpp0x/auto25.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto25.C (revision 0)
+++ testsuite/g++.dg/cpp0x/auto25.C (revision 0)
@@ -0,0 +1,7 @@
+// PR c++/42056
+// { dg-options -std=c++0x }
+
+template<int> struct A
+{
+ int a[auto(1)]; // { dg-error "invalid use of" }
+};
Index: testsuite/g++.dg/cpp0x/auto26.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto26.C (revision 0)
+++ testsuite/g++.dg/cpp0x/auto26.C (revision 0)
@@ -0,0 +1,7 @@
+// PR c++/42056
+// { dg-options -std=c++0x }
+
+template<int> void foo()
+{
+ int a[auto(1)]; // { dg-error "invalid use of" }
+}
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 174301)
+++ cp/typeck2.c (working copy)
@@ -1603,6 +1603,14 @@ build_functional_cast (tree exp, tree parms, tsubs
{
tree t;
+ if (type_uses_auto (type))
+ {
+ if (complain & tf_error)
+ error ("invalid use of %<auto%>");
+ else
+ return error_mark_node;
+ }
+
/* Diagnose this even in a template. We could also try harder
to give all the usual errors when the type and args are
non-dependent... */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 42056
2011-05-26 19:38 [C++ Patch] PR 42056 Paolo Carlini
@ 2011-05-26 20:23 ` Paolo Carlini
2011-05-27 7:20 ` Jason Merrill
1 sibling, 0 replies; 6+ messages in thread
From: Paolo Carlini @ 2011-05-26 20:23 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
On 05/26/2011 08:30 PM, Paolo Carlini wrote:
> ...also, not returning error_mark_node unconditionally, means a better
> diagnostic, without redundant "array bound is not an integer constant
> before...".
Just noticed that outside a template, we do indeed emit the additional
"array bound is not an integer constant before..." message. If we want
it, I have just to return error_mark_node unconditionally. Just let me know.
Paolo.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 42056
2011-05-26 19:38 [C++ Patch] PR 42056 Paolo Carlini
2011-05-26 20:23 ` Paolo Carlini
@ 2011-05-27 7:20 ` Jason Merrill
2011-05-27 12:04 ` Paolo Carlini
1 sibling, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-05-27 7:20 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
On 05/26/2011 02:30 PM, Paolo Carlini wrote:
> We want to do that only when processing a template, because otherwise we
> get a duplicate diagnostic, see, eg, auto9.C
Hmm, where's the error coming from in the non-template case? From
cp_build_c_cast? In that case always giving the error in
build_functional_cast and then returning error_mark_node should avoid
duplication.
> error_mark_node unconditionally, means a better diagnostic, without
> redundant "array bound is not an integer constant before...".
I'd rather deal with that by suppressing that error if we already have
error_mark_node.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 42056
2011-05-27 7:20 ` Jason Merrill
@ 2011-05-27 12:04 ` Paolo Carlini
2011-05-27 14:26 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2011-05-27 12:04 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1050 bytes --]
Hi,
> On 05/26/2011 02:30 PM, Paolo Carlini wrote:
>> We want to do that only when processing a template, because otherwise we
>> get a duplicate diagnostic, see, eg, auto9.C
> Hmm, where's the error coming from in the non-template case? From
> cp_build_c_cast? In that case always giving the error in
> build_functional_cast and then returning error_mark_node should avoid
> duplication.
I should have told you. The error is produced via
complete_type_or_maybe_complain called from line 1650 of
build_functional_cast itself, by cxx_incomplete_type_diagnostic.
>> error_mark_node unconditionally, means a better diagnostic, without
>> redundant "array bound is not an integer constant before...".
> I'd rather deal with that by suppressing that error if we already have
> error_mark_node.
complete_type_or_maybe_complain, when type is an error_mark_node
understands that an error has been produced already and simply returns
NULL_TREE. Thus, something like the below works. Is it closer to what
you had in mind?
Paolo.
/////////////////
[-- Attachment #2: CL_42056_2 --]
[-- Type: text/plain, Size: 355 bytes --]
/cp
2011-05-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42056
* typeck2.c (build_functional_cast): Complain early for invalid uses
of 'auto' and set type to error_mark_node.
/testsuite
2011-05-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42056
* testsuite/g++.dg/cpp0x/auto25.C: New.
* testsuite/g++.dg/cpp0x/auto26.C: Likewise.
[-- Attachment #3: patch_42056_2 --]
[-- Type: text/plain, Size: 1177 bytes --]
Index: testsuite/g++.dg/cpp0x/auto25.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto25.C (revision 0)
+++ testsuite/g++.dg/cpp0x/auto25.C (revision 0)
@@ -0,0 +1,7 @@
+// PR c++/42056
+// { dg-options -std=c++0x }
+
+template<int> struct A
+{
+ int a[auto(1)]; // { dg-error "invalid use of" }
+};
Index: testsuite/g++.dg/cpp0x/auto26.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto26.C (revision 0)
+++ testsuite/g++.dg/cpp0x/auto26.C (revision 0)
@@ -0,0 +1,7 @@
+// PR c++/42056
+// { dg-options -std=c++0x }
+
+template<int> void foo()
+{
+ int a[auto(1)]; // { dg-error "invalid use of" }
+}
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 174321)
+++ cp/typeck2.c (working copy)
@@ -1599,6 +1599,13 @@ build_functional_cast (tree exp, tree parms, tsubs
return error_mark_node;
}
+ if (type_uses_auto (type))
+ {
+ if (complain & tf_error)
+ error ("invalid use of %<auto%>");
+ type = error_mark_node;
+ }
+
if (processing_template_decl)
{
tree t;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 42056
2011-05-27 12:04 ` Paolo Carlini
@ 2011-05-27 14:26 ` Jason Merrill
2011-05-27 16:36 ` Paolo Carlini
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-05-27 14:26 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
OK, but please combine those tests into one file.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [C++ Patch] PR 42056
2011-05-27 14:26 ` Jason Merrill
@ 2011-05-27 16:36 ` Paolo Carlini
0 siblings, 0 replies; 6+ messages in thread
From: Paolo Carlini @ 2011-05-27 16:36 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 141 bytes --]
On 05/27/2011 03:57 PM, Jason Merrill wrote:
> OK, but please combine those tests into one file.
Thanks. As applied.
Paolo.
//////////////
[-- Attachment #2: CL_42056_3 --]
[-- Type: text/plain, Size: 309 bytes --]
/cp
2011-05-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42056
* typeck2.c (build_functional_cast): Complain early for invalid uses
of 'auto' and set type to error_mark_node.
/testsuite
2011-05-27 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/42056
* testsuite/g++.dg/cpp0x/auto25.C: New.
[-- Attachment #3: patch_42056_3 --]
[-- Type: text/plain, Size: 910 bytes --]
Index: testsuite/g++.dg/cpp0x/auto25.C
===================================================================
--- testsuite/g++.dg/cpp0x/auto25.C (revision 0)
+++ testsuite/g++.dg/cpp0x/auto25.C (revision 0)
@@ -0,0 +1,12 @@
+// PR c++/42056
+// { dg-options -std=c++0x }
+
+template<int> struct A
+{
+ int a[auto(1)]; // { dg-error "invalid use of" }
+};
+
+template<int> void foo()
+{
+ int a[auto(1)]; // { dg-error "invalid use of" }
+}
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c (revision 174324)
+++ cp/typeck2.c (working copy)
@@ -1599,6 +1599,13 @@ build_functional_cast (tree exp, tree parms, tsubs
return error_mark_node;
}
+ if (type_uses_auto (type))
+ {
+ if (complain & tf_error)
+ error ("invalid use of %<auto%>");
+ type = error_mark_node;
+ }
+
if (processing_template_decl)
{
tree t;
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-05-27 14:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-26 19:38 [C++ Patch] PR 42056 Paolo Carlini
2011-05-26 20:23 ` Paolo Carlini
2011-05-27 7:20 ` Jason Merrill
2011-05-27 12:04 ` Paolo Carlini
2011-05-27 14:26 ` Jason Merrill
2011-05-27 16:36 ` Paolo Carlini
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).