This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gcc warnings and [in]valid lvals


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]