This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] fix PR c++/14136: Duplicate error message
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: rasky at develer dot com
- Cc: gcc-patches at gcc dot gnu dot org, nathan at codesourcery dot com
- Date: Fri, 03 Dec 2004 15:21:15 +0100 (CET)
- Subject: Re: [patch] fix PR c++/14136: Duplicate error message
On 2 Dec, Giovanni Bajo wrote:
> Volker Reichelt <reichelt@igpm.rwth-aachen.de> wrote:
>
>> For the following code snippet we issue a duplicate diagnostic on
> mainline:
>>
>> ==========================
>> struct A
>> {
>> typedef A B;
>> ~B();
>> };
>> ==========================
>>
>> PR14136.cc:4: error: typedef-name 'A::B' used as destructor declarator
>> PR14136.cc:4: error: typedef-name 'A::B' used as destructor declarator
>>
>> This is because we issue the error when we are parsing the declaration
>> tentatively and then again when we parse it for real.
>>
>> The following patch fixes that by not issuing the error message when we
>> do tentative parsing only.
>
> I don't recall us doing a check like this to avoid error messages anywhere
> else in the parser. Usually, we use cp_parser_error: in tentative parsing,
> it does not emit the error message but marks the parsing attempt as failed;
> in non-tenative parsing, it emits a normal error message.
>
> So I am not sure this is the correct way to go.
Good point.
Alas, cp_parser_error can only deal with a simple string, and not with
"%qD" which is used to output the typedef-name. In cp_parser_lookup_name
occured a similar problem. It is dealt with in the following way:
/* The error message we have to print is too complicated for
cp_parser_error, so we incorporate its actions directly. */
if (!cp_parser_simulate_error (parser))
{
error ("reference to %qD is ambiguous", name);
print_candidates (decl);
}
In fact, cp_parser_simulate_error in fact calls
!cp_parser_committed_to_tentative_parse, but does some additional
stuff (like marking the attempt as failed), too.
So here's an updated version which uses cp_parser_simulate_error
instead of just cp_parser_committed_to_tentative_parse.
OK to apply to mainline once this passes bootstrap and regtesting?
Regards,
Volker
2004-12-02 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/14136
* parser.c (cp_parser_unqualified_id): Do not issue error message
for typedef-name as destructor declarator when parsing tentatively.
Index: parser.c
===================================================================
RCS file: /usr/local/gcc/CVS/gcc-cvs/gcc/gcc/cp/parser.c,v
retrieving revision 1.276
diff -u -p -r1.276 parser.c
--- parser.c 3 Nov 2004 02:48:37 -0000 1.276
+++ parser.c 27 Nov 2004 07:07:14 -0000
@@ -3234,7 +3234,8 @@ cp_parser_unqualified_id (cp_parser* par
identifier in the declarator for a destructor declaration. */
if (declarator_p
&& !DECL_IMPLICIT_TYPEDEF_P (type_decl)
- && !DECL_SELF_REFERENCE_P (type_decl))
+ && !DECL_SELF_REFERENCE_P (type_decl)
+ && !cp_parser_simulate_error (parser))
error ("typedef-name %qD used as destructor declarator",
type_decl);
===================================================================