From -5930873348882654084
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7522e5259f7267d6,start
X-Google-Attributes: gidf78e5,public
From: smeyers@aristeia.com (Scott Meyers)
Subject: x = y = z;  Undefined?
Date: 2000/01/06
Message-ID: <MPG.12ddaa92533ae9679896a6@news.supernews.com>#1/1
X-Deja-AN: 569068577
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
X-Original-Date: Wed, 5 Jan 2000 19:23:57 -0800
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: ariel.ucs.unimelb.edu.au 947162297 28501 128.250.37.153 (6 Jan 2000 12:38:17 GMT)
Organization: Scott Meyers
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUAOHSM4uEDnX0m9pzZAQH6QAGAn8CSIIQ2Np38Z70S2mwwhbvFFzju4iAh PiNIqAaoV9YqaW11/CSxTcOUbB6aru7d =tfnm
NNTP-Posting-Date: 6 Jan 2000 12:38:17 GMT
Newsgroups: comp.std.c++

I recently received the following mail about something I wrote in EC++/2E:

  A friend of mine was complaining about standard's standpoint with regard
  to RC implementation of strings, and proposed a solution with
  proxy-classes that used op=() returning const, something along the lines
  of:
  
  class retval
  {
      const_reference operator=( ... );
  };
  
  I objected (out of the good practice, since op=() normally returns T&, not
  const T& (for instance all the containers in the STL)). However, when I
  re-read Item 15 of EC++, I didn't quite understand your reasons for
  advocating non-const op=():
  
  [snip -- EC++2ed, Item 15, p 66]
  
  int i1, i2, i3;
  
  ...
  
  (i1 = i2) = i3;   // legal! assigns i2 to i1, then i3 to i1!
  
  [/snip]
  
  AFAIK, parenthesis do not introduce a sequence point (only ";", ",",
  "&&" and "||" do) and the above code modifies an object (i1) twice before
  a seq. point. This is undefined behaviour, according to the standard.

I think he may be right.  So I have two questions:

  1.  Does the above example run afoul of the rule against modifing an
      object more than once without an intervening sequence point?  (In the
      example, it's important that the type in question be a built-in.  For
      user-defined types, assignment is a function call, and different
      rules apply.)

  2.  Why does assignment for built-in types return an lvalue?  My
      understanding is that this is a difference from C, and I know I've
      read reasons for it before, but I can't remember ever reading a
      particularly good reason.

Thanks,

Scott

-- 
Scott Meyers, Ph.D.                  smeyers@aristeia.com
Software Development Consultant      http://www.aristeia.com/
Visit http://meyerscd.awl.com/ to demo the Effective C++ CD
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



