This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc warnings and [in]valid lvals
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Graeme Peterson <gp at qnx dot com>
- Cc: gcc at sources dot redhat dot com
- Date: 12 Nov 2002 23:11:40 +0100
- Subject: Re: gcc warnings and [in]valid lvals
- Organization: Integrable Solutions
- References: <Pine.NTO.4.21.0211121621510.255369251-100000@node128.ott.qnx.com>
Graeme Peterson <gp@qnx.com> writes:
| Hi, all.
|
| Consider the following, where "get_some_string()" may return NULL:
|
| char *str;
| if( (str = get_some_string()) = NULL)
|
| In "C", you get the expected failure: "invalid lvalue in assignment".
| In "C++", since the type info is kept around (or so I think), then this
In C++ (contrary to C), the result of an assignment is an lvalue,
therefore the assignment is valid (even though not you wanted).
[...]
| It seems to me that the first case (which does not generate a warning),
| while valid, is more often the result of a typo than intent.
Maybe so.
| Is this a bug in the warnings code, or expected behavior?
Maybe be a bug in the warning code.
-- Gaby