This is the mail archive of the gcc-help@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: Regarding GCC 4.9.2 backward compatibility with 3.2.1


On 24/08/2017 11:46, Pialy Ghosh wrote:

> The code snippet is like below
> (void *)ShMem = shmat(ShId, 0, 0);
> 
> Error in this line: lvalue required as left operand of assignment.
> 
> 
> From GCC 3.4 lvalue casting is removed.
> Is there any way to solve this error without changing the code? If we
> can use compiler 4.9.2 without any code modification.
> Enabling this support by adding any flag, if any?

Hello,

It is customary to provide a complete minimal test-case
others can compile and test. For example:

$ cat testcase.cxx
extern void *foo(void);
void bar(void)
{
	int *ptr;
	(void *)ptr = foo();
}

$ g++ -Wall -Wextra -O -c testcase.cxx
testcase.cxx: In function 'void bar()':
testcase.cxx:5:14: error: lvalue required as left operand of assignment
  (void *)ptr = foo();
              ^

If the original code was trying to get around this issue:

testcase.cxx: In function 'void bar()':
testcase.cxx:5:12: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
  ptr = foo();
            ^

which is allowed in C, but not in C++, then a cast should have
been used on the rhs expression (not the lhs).

$ cat testcase.cxx 
extern void *foo(void);
void bar(void)
{
	int *ptr;
	ptr = (int *)foo();
}

I'm not aware of any flags to reinstate the cast-as-lvalue extension,
but I'm just a random developer.

Regards.


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