gcc warnings and [in]valid lvals

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Nov 12 14:36:00 GMT 2002


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



More information about the Gcc mailing list