Re: returning lvalue in C vs C++



Alf P. Steinbach wrote:
int main(void)
{
struct thing t = {20};
int y = (f() = t).x;


This is invalid in both C and C++.

Why is this invalid in C++? If I understand correctly, f() returns an rvalue of class type, and therefore you can call the operator= member for it.

For what it's worth, both g++ and Comeau think it is valid.

Alan
.



Relevant Pages

  • Re: Usual arithmetic conversions + integral promotion for short?
    ... > converted to an rvalue of type int if int can represent all the values ... conversions", and which for this case states that the integral promotions ...
    (comp.lang.cpp)
  • A problem with the default constructor
    ... template <class Type> class dataList //数据表类定义 ... int CurrentSize; //数组当前长度 ... compiling class-template member function '__thiscall ...
    (comp.lang.cpp)
  • Re: Help me with a class assignment
    ... This file will consist of the component functions ... prog4Fns.h would have been a better name for the header file. ... int get_grades; ... int index, invalid, sum; ...
    (comp.lang.c)
  • Re: Java RMI JDK1.6 Exception - More Info
    ... I've included the stack trace of the client & server. ... int add; ... Caused by: java.net.SocketException: Invalid argument ...
    (comp.unix.bsd.freebsd.misc)
  • Re: bitwise not and "auto casts"
    ... > An rvalue of type char, signed char, unsigned char, short int, or unsigned short ... > the source rvalue can be converted to an rvalue of type unsigned int. ... > An rvalue of type bool can be converted to an rvalue of type int, with false becoming zero and true ...
    (comp.lang.cpp)