diff mbox

[c++] : Fix PR/64127 ICE on invalid: tree check: exprected identifier_node, have template_id_expr in cp_parser_diagnose_invalid_type_name

Message ID CAEwic4YDKvn=YqzfpKAUyWUEMS-LkCdDwzeOaXd=jt-2n_5-ag@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Dec. 4, 2014, 3:12 p.m. UTC
Hi,

this patch fixes an ICE happening on invalid code for < c++11.  It is
reasoned by
accessing blindly identifier without checking that it is a declaration.

ChangeLog

2014-12-04  Kai Tietz  <ktietz@redhat.com>

    PR c++/64127
    * parser.c (cp_parser_diagnose_invalid_type_name): Check
    id for being a declaration before accessing identifier.

Tested on x86_64-unknown-linux-gnu.

Ok for apply?

Regards,
Kai

Comments

Marek Polacek Dec. 4, 2014, 3:47 p.m. UTC | #1
On Thu, Dec 04, 2014 at 04:12:02PM +0100, Kai Tietz wrote:
> Hi,
> 
> this patch fixes an ICE happening on invalid code for < c++11.  It is
> reasoned by
> accessing blindly identifier without checking that it is a declaration.
> 
> ChangeLog
> 
> 2014-12-04  Kai Tietz  <ktietz@redhat.com>
> 
>     PR c++/64127
>     * parser.c (cp_parser_diagnose_invalid_type_name): Check
>     id for being a declaration before accessing identifier.
> 
> Tested on x86_64-unknown-linux-gnu.
> 
> Ok for apply?

Testcase?

	Marek
Kai Tietz Dec. 4, 2014, 3:59 p.m. UTC | #2
2014-12-04 16:47 GMT+01:00 Marek Polacek <polacek@redhat.com>:
> On Thu, Dec 04, 2014 at 04:12:02PM +0100, Kai Tietz wrote:
>> Hi,
>>
>> this patch fixes an ICE happening on invalid code for < c++11.  It is
>> reasoned by
>> accessing blindly identifier without checking that it is a declaration.
>>
>> ChangeLog
>>
>> 2014-12-04  Kai Tietz  <ktietz@redhat.com>
>>
>>     PR c++/64127
>>     * parser.c (cp_parser_diagnose_invalid_type_name): Check
>>     id for being a declaration before accessing identifier.
>>
>> Tested on x86_64-unknown-linux-gnu.
>>
>> Ok for apply?
>
> Testcase?
>
>         Marek

Same as said before.  Issue is a invalid-code bug with ICE, and
error-messages are pretty meaningless.  It would be helpful to have in
testsuite just the opportunity to test for no ICE.

Anyway, if testcase is requested, I can add it to g++.dg/ collection

Kai
Jakub Jelinek Dec. 4, 2014, 4:32 p.m. UTC | #3
On Thu, Dec 04, 2014 at 04:59:21PM +0100, Kai Tietz wrote:
> Same as said before.  Issue is a invalid-code bug with ICE, and
> error-messages are pretty meaningless.  It would be helpful to have in
> testsuite just the opportunity to test for no ICE.

You can add just // { dg-error "" } on all lines that are diagnosed,
the ICE should FAIL the test anyway.  Please verify it by checking
the testcase fails without the patch and succeeeds with the patch.

> Anyway, if testcase is requested, I can add it to g++.dg/ collection

Yes, please.

	Jakub
Jason Merrill Dec. 4, 2014, 7:35 p.m. UTC | #4
On 12/04/2014 10:12 AM, Kai Tietz wrote:
>         else if (cxx_dialect < cxx11
> +           && DECL_P (id)
>              && !strcmp (IDENTIFIER_POINTER (id), "thread_local"))

This doesn't make any sense: If it's a decl it isn't an identifier.  Did 
you mean to check for IDENTIFIER_NODE?

Jason
Kai Tietz Dec. 4, 2014, 8:05 p.m. UTC | #5
2014-12-04 20:35 GMT+01:00 Jason Merrill <jason@redhat.com>:
> On 12/04/2014 10:12 AM, Kai Tietz wrote:
>>
>>         else if (cxx_dialect < cxx11
>> +           && DECL_P (id)
>>              && !strcmp (IDENTIFIER_POINTER (id), "thread_local"))
>
>
> This doesn't make any sense: If it's a decl it isn't an identifier.  Did you
> mean to check for IDENTIFIER_NODE?
>
> Jason
>

Sure ...
diff mbox

Patch

Index: parser.c
===================================================================
--- parser.c    (Revision 218309)
+++ parser.c    (Arbeitskopie)
@@ -2977,6 +2977,7 @@  cp_parser_diagnose_invalid_type_name (cp_parser *p
     inform (location, "C++11 %<noexcept%> only available with "
         "-std=c++11 or -std=gnu++11");
       else if (cxx_dialect < cxx11
+           && DECL_P (id)
            && !strcmp (IDENTIFIER_POINTER (id), "thread_local"))
     inform (location, "C++11 %<thread_local%> only available with "
         "-std=c++11 or -std=gnu++11");