This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[wwwdocs] Add some C++ bits to porting_to
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jonathan Wakely <jwakely at redhat dot com>
- Date: Thu, 4 Feb 2016 13:37:26 +0100
- Subject: [wwwdocs] Add some C++ bits to porting_to
- Authentication-results: sourceware.org; auth=none
I spotted these two issues in real-world code when doing Fedora mass
rebuild. It's C++ and so I don't really know what I'm talking about;
Jon, could you please look at this?
Thanks,
Index: porting_to.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/porting_to.html,v
retrieving revision 1.3
diff -u -r1.3 porting_to.html
--- porting_to.html 2 Feb 2016 20:34:14 -0000 1.3
+++ porting_to.html 4 Feb 2016 12:33:19 -0000
@@ -107,6 +107,60 @@
bool valid(std::ostream& os) { return (bool)os; }
</code></pre>
+<h4>Lvalue required as left operand of assignment with complex numbers</h4>
+
+<p>
+Since C++11 (as per DR#387) the member functions <code>real()</code> and
+<code>imag()</code> of <code>std::complex</code> can no longer be used as
+lvalues, thus the following code is rejected:
+</p>
+<pre><code>
+ std::complex<double> f;
+ f.real () = val;
+</code></pre>
+
+<p>
+To assign <code>val</code> to the real component of <code>f</code>, the
+following should be used instead:
+</p>
+<pre><code>
+ std::complex<double> f;
+ f.real (val);
+</code></pre>
+
+<h4>Destructors are <code>noexcept</code> by default</h4>
+
+<p>
+In C++11, destructors are implicitly declared as <code>noexcept</code>. In
+practice this means that the following program behaves differently in C++11
+than in C++03:
+</p>
+<pre><code>
+ #include <stdexcept>
+ struct S
+ {
+ ~S() { throw std::runtime_error ("oops"); }
+ };
+ int
+ main (void)
+ {
+ try { S s; }
+ catch (...) {
+ return 42;
+ }
+ }
+</code></pre>
+
+<p>
+While in C++03 this program returns 42, in C++11 it terminates with a call to
+<code>std::terminate</code>. A new warning, <code>-Wterminate</code>, will
+warn about such code. It is possible to restore the old behavior when
+defining the destructor like this:
+</p>
+<pre><code>
+ ~S() noexcept(false) { throw std::runtime_error ("oops"); }
+</code></pre>
+
<h3>Header dependency changes</h3>
<p>
Marek