From -2969531303714423527
X-Google-Thread: f78e5,51456c3eb8f9490e,start
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news4.google.com!news3.google.com!news.glorb.com!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: "Thomas" <thomas@tansasystems.com>
Newsgroups: comp.std.c++
Subject: Copy Constructor Confusion!
Date: Tue, 15 Aug 2006 09:07:41 CST
Organization: http://groups.google.com
Lines: 27
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <1155645873.296811.3890@74g2000cwt.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1155645876 5457 127.0.0.1 (15 Aug 2006 12:44:36 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 15 Aug 2006 12:44:36 +0000 (UTC)
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
User-Agent: G2/0.2
X-HTTP-UserAgent: Opera/9.00 (Windows NT 5.1; U; en),gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: 74g2000cwt.googlegroups.com; posting-host=62.92.16.81;
   posting-account=gGDeBw0AAAAwR55CTLSLj_THviPOPVc8
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Xref: g2news2.google.com comp.std.c++:3265

Hello fellow programmers!

I have a c++ line:

X x = X();

Does the standard say that the class X must have a public copy
constructor for this to be legal, even if the copy constructor never
gets called?

I have experimented with this, and if X's copy constructor is pivate
the compilation fails, but when I run this, with a public copy
constructor, the copy constructor never gets called. So is this legal
for the optimizer, or whatever, to optimize this copy constructor away,
and just create code like I've writen "X x;" ? But the compiler can not
approve the code if it wants to conform to the standard?

If I am right, can anyone explain why it is so? 

-Thomas

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]



