Re: returning lvalue in C vs C++



On 2006-03-31, Alf P. Steinbach <alfps@xxxxxxxx> wrote:
* Alan Johnson wrote, on 31.03.2006 11:14:
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++?

The expression 'f() = t'.

The C++ 1998 standard, §3.10/5, "The result of calling a function that
does not return a reference is an rvalue."

Ah, this was the part I was missing! You did mention it before, but not
with chapter and verse from the standard.

That's quite clear then really. Although as you say it's in a
non-normative "Note", and it sounds like something that's had a bit of a
history and a few changes-of-mind.

Anyway, thanks for the detailed explanation.
.



Relevant Pages

  • -lrmi and -lvbe dont work anymore!?
    ... gtf.h:46: warning: 'struct VesaCRTCInfoBlock' declared inside parameter list ... vo_vesa.c:184: error: invalid use of undefined type 'struct ... vo_vesa.c:582: error: dereferencing pointer to incomplete type ...
    (Debian-User)
  • Re: How much oop is too much oop?
    ... > struct X ... > int m_x; ... > // Here, x is invalid, uninitialized, or whatever you want to call it. ... > CWnd is not like X. ...
    (microsoft.public.vc.language)
  • Re: Error in Accept
    ... My server program shows "Invalid argument" in connectcall. ... int sid,sockfd,sin_size,new_fd,n; ... struct sockaddr_in their_addr; ... bind() doesn't return a socket-fd ... ...
    (comp.unix.programmer)
  • [kde] Kopete + MSN
    ... error: invalid use of incomplete type 'struct Plasma::IconWidget' ... warning: possible problem detected in invocation of delete operator: ... warning: invalid use of incomplete type 'struct Plasma::IconWidget' ... *** Error code 1 ...
    (KDE)
  • NeXTSTEP 3.3 + sendmail 8.13.6
    ... assert.c:78: invalid use of undefined type `struct sm_file' ... *** Exit 1 ...
    (comp.sys.next.programmer)