Bug 33208 - Broken diagnostic: 'component_ref' not supported by dump_decl
Summary: Broken diagnostic: 'component_ref' not supported by dump_decl
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Paolo Carlini
URL:
Keywords: diagnostic, monitored
Depends on:
Blocks:
 
Reported: 2007-08-27 21:34 UTC by Volker Reichelt
Modified: 2007-09-02 13:03 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-09-01 20:03:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2007-08-27 21:34:15 UTC
The following invalid code snippet triggers a broken diagnostic since
at least GCC 2.95.3:

====================
struct A
{
  bool b;
};

void f(A a)
{
  a.b--;
}
====================

bug.cc: In function 'void f(A)':
bug.cc:8: error: invalid use of '--' on bool variable '#'component_ref' not supported by dump_decl#<declaration error>'
Comment 1 Andrew Pinski 2007-09-01 20:03:14 UTC
Confirmed.

The problem is obvious:
                error ("invalid use of %<--%> on bool variable %qD", arg);

%qD should be %qE.

Comment 2 Paolo Carlini 2007-09-01 20:52:16 UTC
But do we really want 'a.A::b' ?!?
Comment 3 Andrew Pinski 2007-09-01 21:01:38 UTC
(In reply to comment #2)
> But do we really want 'a.A::b' ?!?

Well the error message needs rewording also.

Something like:
invalid use of %<--%> on bool lvalue %qE

Comment 4 gdr@cs.tamu.edu 2007-09-01 21:07:55 UTC
Subject: Re:  Broken diagnostic: 'component_ref' not supported by dump_decl

"pcarlini at suse dot de" <gcc-bugzilla@gcc.gnu.org> writes:

| But do we really want 'a.A::b' ?!?

No, we don't.  The format specific is OK -- e.g. it should be %qD.  However,
the caller of error() should make sure it gives a _DECL.  It isn't 
really the diagnostic machinery's business here to second guess
a type error correction.

Of course, it would have been better if we had diagnostics with carret...

-- Gaby
Comment 5 Paolo Carlini 2007-09-01 21:11:13 UTC
Thanks Gaby, let's see what I can do...
Comment 6 Andrew Pinski 2007-09-01 21:12:48 UTC
Another testcase:
void f(bool *b)
{
  (*b)--;
}

And another one:
bool &g(void);

void f(bool *b)
{
  g()--;
}

So variable in the error message does not make sense at all.  We want to use lvalue instead.
Comment 7 Andrew Pinski 2007-09-01 21:15:33 UTC
(In reply to comment #4)
> | But do we really want 'a.A::b' ?!?
> 
> No, we don't.  The format specific is OK -- e.g. it should be %qD.  However,
> the caller of error() should make sure it gives a _DECL.  It isn't 
> really the diagnostic machinery's business here to second guess
> a type error correction.

Actually "variable a" or "variable b" does not make sense here, we really want to use the word lvalue instead of variable as shown by my other two testcases.

Yes I know it is not the diagnostic machinery's business here to second guess a type error correction but I am saying we need to change the error message fully.  We should not be using "variable %qD" when we can get any kind of lvalues here.

-- Pinski
Comment 8 gdr@cs.tamu.edu 2007-09-01 21:59:13 UTC
Subject: Re:  Broken diagnostic: 'component_ref' not supported by dump_decl

"pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| Another testcase:
| void f(bool *b)
| {
|   (*b)--;
| }
| 
| And another one:
| bool &g(void);
| 
| void f(bool *b)
| {
|   g()--;
| }

Interesting testcase.  This makes me revise my previous opinion to:

  we should not use any of the format specifier at all -- not %qD, not %qE.

| So variable in the error message does not make sense at all.  We want to use
| lvalue instead.

What has this to do with lvalue?  I believe the restriction is that,
it just does not make any sense to decrement a bool -- be it an lvalue
or an rvalue.

Paolo, what about

 error ("invalid use of Boolean expression as operand to %<operator--%>")

?

-- Gaby
Comment 9 Paolo Carlini 2007-09-01 22:14:27 UTC
(In reply to comment #8)
> Paolo, what about
> 
>  error ("invalid use of Boolean expression as operand to %<operator--%>")
> 
> ?

Cetainly works for me...
Comment 10 paolo@gcc.gnu.org 2007-09-02 13:02:52 UTC
Subject: Bug 33208

Author: paolo
Date: Sun Sep  2 13:02:31 2007
New Revision: 128025

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128025
Log:
/cp
2007-09-02  Paolo Carlini  <pcarlini@suse.de>

	PR c++/33208
	* typeck.c (build_unary_op): Fix error message for
	Boolean expression as operand to operator--.

/testsuite
2007-09-02  Paolo Carlini  <pcarlini@suse.de>

	PR c++/33208
	* g++.dg/other/error18.C: New.
	* g++.dg/expr/bitfield3.C: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/other/error18.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/expr/bitfield3.C

Comment 11 Paolo Carlini 2007-09-02 13:03:32 UTC
Fixed.