This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ Patch] Prefer error + inform to two errors in check_template_shadow


Hi again,

On 07/14/2015 05:43 PM, Paolo Carlini wrote:
Hi,

On 07/14/2015 05:07 PM, Jason Merrill wrote:
On 07/13/2015 09:41 AM, Paolo Carlini wrote:
+++ testsuite/g++.dg/template/crash81.C (working copy)
@@ -3,6 +3,6 @@
  struct A
  {
template<T::X> struct X; // { dg-error "'T' has not been declared" "T" } - // { dg-error "declaration of 'template<int X> struct A::X'" "A::X" { target *-*-* } 5 } - // { dg-error "shadows template parm 'int X'" "shadow" { target *-*-* } 5 } + // { dg-error "declaration of 'template<int X> struct A::X' shadows" "A::X" { target *-*-* } 5 }
+  // { dg-message "template parameter 'X'" "" { target *-*-* } 5 }

I don't see any reason to check for specific diagnostics here; the latter two messages are poor error-recovery, not something to test for.
Indeed, I noticed the error recovery issue, which I didn't know, and considered looking into it, when I'm done with some other things. In the meanwhile I'm shortening the expected error/inform.
I had a look and tried various things... Ultimately the issue is due to the type_was_error_mark_node becomes integer_type_node trick in grokdeclarator (which I don't like that much ;) Thus for this testcase the latter simply returns a PARM_DECL of that type and no trace remains of the error, then the following bad error recovery. Now, cp_parser_template_parameter knows how to handle error_mark_node thus in principle we should be able to just return it and be done. The only problem with that, testsuite-wise, is the very broken cpp/pr64127.C which ends up regressing, since we emit a spurious additional error about "default argument for template parameter for class enclosing" from check_default_tmpl_args. Note that for this specific testcase grokdeclarator gets also a null declarator thus for it isn't the same if grokdeclarator returns error_mark_node immediately or just sets type = error_mark_node at the beginning (which results in grokdeclarator not returning an error_mark_node, instead a PARM_DECL with error_mark_node as type).

Thus I have two different proposals: 1- More conservative, just set type = error_mark_node instead of integer_type_node when we have a template parameter; 2- Return error_mark_node immediately and adjust check_default_tmpl_args to cope correctly with pr64127.C.

Thanks!
Paolo.

Attachment: patch_error_recovery
Description: Text document

Attachment: patch_error_recovery_2
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]