public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [wwwdocs] Document null 'this' dereference issue in /gcc-6/porting_to.html
@ 2016-02-09 21:06 Jonathan Wakely
  2016-02-11 10:39 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2016-02-09 21:06 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

This adds a note to the porting document about the (shockingly
widespread) problem of calling member functions through null pointers,
which GCC 6 no longer tolerates.

Following some comments about (bool)os I'm also tweaking another part
of the doc to use the plusplusgood static_cast form.

Committed to CVS.

[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1758 bytes --]

Index: htdocs/gcc-6/porting_to.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/porting_to.html,v
retrieving revision 1.6
diff -u -r1.6 porting_to.html
--- htdocs/gcc-6/porting_to.html	4 Feb 2016 16:50:41 -0000	1.6
+++ htdocs/gcc-6/porting_to.html	9 Feb 2016 19:35:59 -0000
@@ -106,13 +106,11 @@
 
 <p>
 Such code must be changed to convert the iostream object to <code>bool</code>
-explicitly:
+explicitly, e.g. <code>return (bool)os;</code>
+or
+<code>return static_cast&lt;bool&gt;(os);</code>
 </p>
 
-<pre><code>
-  bool valid(std::ostream&amp; os) { return (bool)os; }
-</code></pre>
-
 <h4>Lvalue required as left operand of assignment with complex numbers</h4>
 
 <p>
@@ -222,6 +220,25 @@
 the C++ standard library.
 </p>
 
+<h3>Optimizations remove null pointer checks for <code>this</code></h3>
+
+<p>
+When optimizing, GCC now assumes the <code>this</code> pointer can never be
+null, which is guaranteed by the language rules. Invalid programs which 
+assume it is OK to invoke a member function through a null pointer (possibly
+relying on checks like <code>this != NULL</code>) may crash or otherwise fail
+at run-time if null pointer checks are optimized away.
+With the <code>-Wnull-dereference</code> option the compiler tries to warn
+when it detects such invalid code.
+</p>
+
+<p>
+If the program cannot be fixed to remove the undefined behaviour then the
+option <code>-fno-delete-null-pointer-checks</code> can be used to disable
+this optimization. That option also disables other optimizations involving
+pointers, not only those involving <code>this</code>.
+</p>
+
 <h2>-Wmisleading-indentation</h2>
 <p>
 A new warning <code>-Wmisleading-indentation</code> was added

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

* Re: [wwwdocs] Document null 'this' dereference issue in /gcc-6/porting_to.html
  2016-02-09 21:06 [wwwdocs] Document null 'this' dereference issue in /gcc-6/porting_to.html Jonathan Wakely
@ 2016-02-11 10:39 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2016-02-11 10:39 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 434 bytes --]

On 09/02/16 21:06 +0000, Jonathan Wakely wrote:
>This adds a note to the porting document about the (shockingly
>widespread) problem of calling member functions through null pointers,
>which GCC 6 no longer tolerates.
>
>Following some comments about (bool)os I'm also tweaking another part
>of the doc to use the plusplusgood static_cast form.
>
>Committed to CVS.

Tweak to conform to our spelling conventions.

Committed to CVS.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1186 bytes --]

Index: htdocs/gcc-6/porting_to.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/porting_to.html,v
retrieving revision 1.9
diff -u -r1.9 porting_to.html
--- htdocs/gcc-6/porting_to.html	10 Feb 2016 17:21:54 -0000	1.9
+++ htdocs/gcc-6/porting_to.html	11 Feb 2016 10:34:43 -0000
@@ -248,13 +248,13 @@
 null, which is guaranteed by the language rules. Invalid programs which 
 assume it is OK to invoke a member function through a null pointer (possibly
 relying on checks like <code>this != NULL</code>) may crash or otherwise fail
-at run-time if null pointer checks are optimized away.
+at run time if null pointer checks are optimized away.
 With the <code>-Wnull-dereference</code> option the compiler tries to warn
 when it detects such invalid code.
 </p>
 
 <p>
-If the program cannot be fixed to remove the undefined behaviour then the
+If the program cannot be fixed to remove the undefined behavior then the
 option <code>-fno-delete-null-pointer-checks</code> can be used to disable
 this optimization. That option also disables other optimizations involving
 pointers, not only those involving <code>this</code>.

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

end of thread, other threads:[~2016-02-11 10:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-09 21:06 [wwwdocs] Document null 'this' dereference issue in /gcc-6/porting_to.html Jonathan Wakely
2016-02-11 10:39 ` Jonathan Wakely

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).