[Bug c/57647] New: lvalue required as increment operand

vijunag at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Jun 19 06:38:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57647

            Bug ID: 57647
           Summary: lvalue required as increment operand
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vijunag at gmail dot com

I recently upgraded my gcc compiler from 3.4.X to 4.7.2 for my project.

Consider the following expression

char *foo = &bar;
((unsigned long*)foo)++

While gcc 3.4.X was more forgiving of this issue, 4.7.2 barfs out an error
"lvalue required as increment operand".

I did notice in gcc documentation that "cast as l-value has been removed".

C and Objective-C

    The -Wstrict-aliasing=2 option has been added. This warning catches all
unsafe cases, but it may also give a warning for some cases that are safe.
    The cast-as-lvalue, conditional-expression-as-lvalue and
compound-expression-as-lvalue extensions, which were deprecated in 3.3.4 and
3.4, have been removed.
    The -fwritable-strings option, which was deprecated in 3.4, has been
removed.
    #pragma pack() semantics have been brought closer to those used by other
compilers. This also applies to C++.
    Taking the address of a variable with register storage is invalid in C. GCC
now issues an error instead of a warning.
    Arrays of incomplete element type are invalid in C. GCC now issues an error
for such arrays. Declarations such as extern struct s x[]; (where struct s has
not been defined) can be moved after the definition of struct s. Function
parameters declared as arrays of incomplete type can instead be declared as
pointers.

So the natural fix and equivalent legitimate expression for the same would 
((unsigned long *)foo++), however with -Wall gcc again warns about
unused-value.

While gcc accepts the expression ((unsigned long*)foo++), the expression has
become useless when -Wall -Werror  is turned on since it throws
"-Werror=unused-value".

Either the expression should completely be removed or GCC should stop warning
about such expressions.



More information about the Gcc-bugs mailing list