diff mbox

[wwwdocs] Document C++ null pointer constant changes in gcc-7/porting_to.html

Message ID 20170407092521.GA3733@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely April 7, 2017, 9:25 a.m. UTC
This issue caused a lot of build failures during the GCC mass rebuilds
for Fedora, but isn't in the porting to guide yet.

Is this accurate and clear enough for casual readers?

Comments

Marek Polacek April 7, 2017, 9:33 a.m. UTC | #1
On Fri, Apr 07, 2017 at 10:25:21AM +0100, Jonathan Wakely wrote:
> This issue caused a lot of build failures during the GCC mass rebuilds
> for Fedora, but isn't in the porting to guide yet.
> 
> Is this accurate and clear enough for casual readers?

Looks fine to me.

> Index: htdocs/gcc-7/porting_to.html
> ===================================================================
> RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-7/porting_to.html,v
> retrieving revision 1.13
> diff -u -r1.13 porting_to.html
> --- htdocs/gcc-7/porting_to.html	6 Apr 2017 17:12:16 -0000	1.13
> +++ htdocs/gcc-7/porting_to.html	7 Apr 2017 09:25:06 -0000
> @@ -118,6 +118,39 @@
>  with GCC 7 and some are compiled with older releases.
>  </p>
>  
> +<h3 id="null-pointer-constants">Null pointer constants</h3>
> +
> +<p>
> +When compiling as C++11 or later, GCC 7 follows the revised definition of a
> +<em>null pointer constant</em>. This means conversions to pointers from other
> +types of constant (such as character literals and boolean literals) will now
> +be rejected.
> +</p>
> +
> +<pre><code>void* f() {
> +  char* p = '\0';
> +  return false;
> +}
> +</code></pre>
> +
> +      <blockquote><pre>
> +<span class="boldred">error:</span> invalid conversion from <b>'char'</b> to <b>'char*'</b> [<span class="boldred">-fpermissive</span>]
> +   char* p = <span class="boldred">'\0'</span>;
> +             <span class="boldred">^~~~</span>
> +<span class="boldred">error:</span> cannot convert <b>'bool'</b> to <b>'void*'</b> in return
> +   return <span class="boldred">false</span>;
> +          <span class="boldred">^~~~~</span>
> +</pre></blockquote>
> +
> +<p>
> +Such code should be fixed to use a valid null pointer constant such as
> +<code>0</code> or <code>nullptr</code>. Care should be taken when fixing
> +invalid uses of <code>'\0'</code> as a pointer, as it may not be clear whether
> +the intention was to create a null pointer (<code>p = 0;</code>), to create an
> +empty string (<code>p = "";</code>), or to write a null terminator to the
> +string (<code>*p = '\0';</code>).
> +</p>
> +
>  <h3 id="header-dep-changes">Header dependency changes</h3>
>  
>  <p>


	Marek
Sandra Loosemore April 10, 2017, 1:58 a.m. UTC | #2
On 04/07/2017 03:25 AM, Jonathan Wakely wrote:
> This issue caused a lot of build failures during the GCC mass rebuilds
> for Fedora, but isn't in the porting to guide yet.
>
> Is this accurate and clear enough for casual readers?
>
>
> Index: htdocs/gcc-7/porting_to.html
> ===================================================================
> RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-7/porting_to.html,v
> retrieving revision 1.13
> diff -u -r1.13 porting_to.html
> --- htdocs/gcc-7/porting_to.html	6 Apr 2017 17:12:16 -0000	1.13
> +++ htdocs/gcc-7/porting_to.html	7 Apr 2017 09:25:06 -0000
> @@ -118,6 +118,39 @@
>  with GCC 7 and some are compiled with older releases.
>  </p>
>
> +<h3 id="null-pointer-constants">Null pointer constants</h3>
> +
> +<p>
> +When compiling as C++11 or later, GCC 7 follows the revised definition of a
> +<em>null pointer constant</em>. This means conversions to pointers from other
> +types of constant (such as character literals and boolean literals) will now
> +be rejected.
> +</p>

Nit pick: s/will now be rejected/are now rejected/

since "now" means we are describing GCC's current behavior, not future 
behavior.  :-)

-Sandra
diff mbox

Patch

Index: htdocs/gcc-7/porting_to.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-7/porting_to.html,v
retrieving revision 1.13
diff -u -r1.13 porting_to.html
--- htdocs/gcc-7/porting_to.html	6 Apr 2017 17:12:16 -0000	1.13
+++ htdocs/gcc-7/porting_to.html	7 Apr 2017 09:25:06 -0000
@@ -118,6 +118,39 @@ 
 with GCC 7 and some are compiled with older releases.
 </p>
 
+<h3 id="null-pointer-constants">Null pointer constants</h3>
+
+<p>
+When compiling as C++11 or later, GCC 7 follows the revised definition of a
+<em>null pointer constant</em>. This means conversions to pointers from other
+types of constant (such as character literals and boolean literals) will now
+be rejected.
+</p>
+
+<pre><code>void* f() {
+  char* p = '\0';
+  return false;
+}
+</code></pre>
+
+      <blockquote><pre>
+<span class="boldred">error:</span> invalid conversion from <b>'char'</b> to <b>'char*'</b> [<span class="boldred">-fpermissive</span>]
+   char* p = <span class="boldred">'\0'</span>;
+             <span class="boldred">^~~~</span>
+<span class="boldred">error:</span> cannot convert <b>'bool'</b> to <b>'void*'</b> in return
+   return <span class="boldred">false</span>;
+          <span class="boldred">^~~~~</span>
+</pre></blockquote>
+
+<p>
+Such code should be fixed to use a valid null pointer constant such as
+<code>0</code> or <code>nullptr</code>. Care should be taken when fixing
+invalid uses of <code>'\0'</code> as a pointer, as it may not be clear whether
+the intention was to create a null pointer (<code>p = 0;</code>), to create an
+empty string (<code>p = "";</code>), or to write a null terminator to the
+string (<code>*p = '\0';</code>).
+</p>
+
 <h3 id="header-dep-changes">Header dependency changes</h3>
 
 <p>