This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [WWW PATCH] [PR14618] Document new access checking performed by g++


Gerald Pfeifer wrote:

> The patch is fine with these changes (or others which address my
> comments).

This is what I just committed. I also tweaked the example code to be valid
besides the new error I was trying to show (yuck!), and obvious whitespace
changes here and there.

Thanks,
Giovanni Bajo


Index: bugs.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/bugs.html,v
retrieving revision 1.82
diff -c -3 -p -r1.82 bugs.html
*** bugs.html 13 Jan 2004 17:36:40 -0000 1.82
--- bugs.html 21 Mar 2004 01:01:35 -0000
*************** a parse error before the character <code
*** 685,690 ****
--- 685,733 ----
  <p>The simplest way to avoid this is to write <code>std::vector&lt;
  ::X&gt;</code>, i.e. place a space between the opening angle bracket
  and the scope operator.</p></dd>
+
+
+ <dt><a name="cxx_rvalbind">Copy constructor access check while
+ initializing a reference.</a></dt>
+
+ <dd><p>Consider this code:</p>
+
+ <blockquote><pre>
+ class A
+ {
+ public:
+   A();
+
+ private:
+   A(const A& );   // private copy ctor
+ };
+
+ A makeA(void);
+ void foo(const A& a);
+
+ void bar(void)
+ {
+   foo(A());       // error, copy ctor is not accessible
+   foo(makeA());   // error, copy ctor is not accessible
+
+   A a1;
+   foo(a1);        // OK, a1 is a lvalue
+ }</pre></blockquote>
+
+ <p>Starting with GCC 3.4.0, binding an rvalue to a const reference requires
+ an accessible copy constructor. This might be surprising at first sight,
+ especially since most popular compilers do not correctly implement this
+ rule.</p>
+
+ <p>The C++ Standard says that a temporary object should be created in
+ this context and its contents filled with a copy of the object we are
+ trying to bind to the reference; it also says that the temporary copy
+ can be elided, but the semantic constraints (eg. accessibility) of the
+ copy constructor still have to be checked.</p>
+
+ <p>For further information, you can consult the following paragraphs of
+ the C++ standard: [dcl.init.ref]/5, bullet 2, sub-bullet 1, and
+ [class.temporary]/2.</p></dd>
  </dl>

  <h3><a name="upgrading">Common problems when upgrading the compiler</a></h3>
Index: gcc-3.4/changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-3.4/changes.html,v
retrieving revision 1.104
diff -c -3 -p -r1.104 changes.html
*** gcc-3.4/changes.html 15 Mar 2004 08:19:12 -0000 1.104
--- gcc-3.4/changes.html 21 Mar 2004 01:01:36 -0000
***************
*** 529,539 ****
   template class Q&lt;0&gt;;   // OK</pre></li>

      <li>When allocating an array with a new expression, GCC used to allow
!     parentheses around the type name. This is actually ill-formed and it is
!     now rejected:
!     <pre>
!     int* a = new (int)[10];    // error, not accepted anymore
!     int* a = new int[10];      // OK</pre></li>
    </ul>

  <h3>Objective-C</h3>
--- 529,568 ----
   template class Q&lt;0&gt;;   // OK</pre></li>

      <li>When allocating an array with a new expression, GCC used to allow
!  parentheses around the type name. This is actually ill-formed and it is
!  now rejected:
!  <pre>
!  int* a = new (int)[10];    // error, not accepted anymore
!  int* a = new int[10];      // OK</pre></li>
!
!     <li>When binding an rvalue of class type to a reference, the copy
!  constructor of the class must be accessible. For instance, consider
!  the following code:
!  <pre>
!  class A
!  {
!  public:
!    A();
!
!  private:
!    A(const A& );   // private copy ctor
!  };
!
!  A makeA(void);
!  void foo(const A& a);
!
!  void bar(void)
!  {
!    foo(A());       // error, copy ctor is not accessible
!    foo(makeA());   // error, copy ctor is not accessible
!
!    A a1;
!    foo(a1);        // OK, a1 is a lvalue
!  }</pre>
!
!  This might be surprising at first sight, especially since most
!  popular compilers do not correctly implement this rule
!  (<a href="../bugs.html#cxx_rvalbind">further details</a>).</li>
    </ul>

  <h3>Objective-C</h3>




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]