This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Regarding GCC 4.9.2 backward compatibility with 3.2.1
- From: Mason <slash dot tmp at free dot fr>
- To: Pialy Ghosh <pink dot pia at gmail dot com>
- Cc: GCC help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 24 Aug 2017 13:09:38 +0200
- Subject: Re: Regarding GCC 4.9.2 backward compatibility with 3.2.1
- Authentication-results: sourceware.org; auth=none
- References: <CANL=Od6eo9nyV5y_7w8xNyPgzrJYdoZ5Yup-VQrF9=OFAdnAeg@mail.gmail.com> <b7cd0256-4122-f0bb-3d0f-1dd75d26f78a@free.fr> <CANL=Od6LHzOZe4wzVXm+y_BUsEbWKOfeWrMBKb71Ne_hxV_MLA@mail.gmail.com>
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.