public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12226] New: g++ fails to enforce accessibility requirement for copy constructor
@ 2003-09-09 17:46 austern at apple dot com
  2003-09-09 17:47 ` [Bug c++/12226] " austern at apple dot com
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: austern at apple dot com @ 2003-09-09 17:46 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12226

           Summary: g++ fails to enforce accessibility requirement for copy
                    constructor
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: austern at apple dot com
                CC: gcc-bugs at gcc dot gnu dot org,gdr at integrable-
                    solutions dot net
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu

Consider the following code snippet, which is very similar to an example near the end of section 
8.5.3 in the C++ standard.
  struct A { protected: A(const A&); };
  struct B : public A { public: B(const B&); };
  extern B f();
  const A& ra = f();
Even with -W -Wall, this compiles cleanly with no diagnostics.

This is wrong.  This example is ill-formed, and a diagnostic is required.  A's copy constructor is not 
accessible in the initialization of ra, and the standard requires it to be.  From section 8.5.3, 
paragraph 5: "If the initializer expression is an rvalue, with T2 a class type, and cv1 T1 is 
reference-compatible with cv2 T2, the reference is bound in one of the following ways [description 
of the two ways omitted] ... The constructor that would be used to make the copy shall be callable 
whether or not the copy is actually done."

I believe that http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3471 was an incorrect fix, and that it 
disabled some correct diagnostics.  Accessibility checking is required whether or not the copy 
constructor is invoked, because eliding the copy constructor is just an optimization and 
correctness of a program does not depend on how smart a compiler's optimizer happens to be.


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2004-08-27  9:00 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-09 17:46 [Bug c++/12226] New: g++ fails to enforce accessibility requirement for copy constructor austern at apple dot com
2003-09-09 17:47 ` [Bug c++/12226] " austern at apple dot com
2003-09-09 18:02 ` austern at apple dot com
2003-09-09 18:55 ` bangerth at dealii dot org
2003-10-14 16:39 ` pinskia at gcc dot gnu dot org
2003-10-18  2:55 ` [Bug c++/12226] [3.3/3.4 Regression] " pinskia at gcc dot gnu dot org
2003-12-20  4:15 ` pinskia at gcc dot gnu dot org
2003-12-29 17:58 ` pinskia at gcc dot gnu dot org
2004-01-04 22:42 ` cvs-commit at gcc dot gnu dot org
2004-01-04 22:44 ` [Bug c++/12226] [3.3 " mmitchel at gcc dot gnu dot org
2004-01-05 22:52 ` dbaron at dbaron dot org
2004-01-06  0:48 ` mark at codesourcery dot com
2004-02-02 22:17 ` pinskia at gcc dot gnu dot org
2004-08-27  8:46 ` pinskia at gcc dot gnu dot org
2004-08-27  8:48 ` pinskia at gcc dot gnu dot org
2004-08-27  8:48 ` pinskia at gcc dot gnu dot org
2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
2004-08-27  8:51 ` pinskia at gcc dot gnu dot org
2004-08-27  9:00 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).