Patchwork [wwwdocs] gcc-4.6/porting_to.html

login
register
mail settings
Submitter Benjamin Kosnik
Date March 17, 2011, 6:51 a.m.
Message ID <20110316235130.1f44d808@shotwell>
Download mbox | patch
Permalink /patch/87344/
State New
Headers show

Comments

Benjamin Kosnik - March 17, 2011, 6:51 a.m.
Needs some more work, here's a rough draft.

-benjamin
Hans-Peter Nilsson - March 17, 2011, 7:59 a.m.
On Wed, 16 Mar 2011, Benjamin Kosnik wrote:
> Needs some more work, here's a rough draft.

s/Porting to the new tools/Porting to the new version/
?

brgds, H-P
Jakub Jelinek - March 17, 2011, 8:10 a.m.
On Wed, Mar 16, 2011 at 11:51:30PM -0700, Benjamin Kosnik wrote:
> + <p>
> + To fix, first see if the unused variable or parameter can be removed
> + without changing the result or logic of the surrounding code. If not,
> + annoate it with <code>__attribute__((__unused__))</code>

annotate

Also, I think we should mention that casting the var to void is another
option.

And I think it is worth mentioning that sometimes the RHS can have important
side-effects, in which case it is desirable to just drop the LHS and =,
while sometimes the RHS is just uselessly computed and can be dropped
altogether with the assignment and unused variable.

> + <h4>Strict overflow warnings</h4>
> + 
> + <p>
> + Using the <code>-Wstrict-overflow</code> flag
> + with <code>-Werror</code> and optmization flags above <code>-O2</code>
> + may result in compile errors when using glibc optimizations
> + for <code>strcmp</code>.
> + </p>
> + 
> + <p>
> + For example,
> + </p>
> + 
> + <pre>
> + #include <string.h>
> + void do_rm_rf (const char *p) { if (strcmp (p, "/") == 0) return; }
> + </pre>

This has been actually fixed, so we shouldn't mention this.

> + <p>
> + Jim Meyering, <a href="http://lists.fedoraproject.org/pipermail/devel/2011-March/149355.html">gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?</a>

And this reference too.

Thanks for writing this.

	Jakub
Ryan Hill - March 17, 2011, 11:51 a.m.
On Wed, 16 Mar 2011 23:51:30 -0700
Benjamin Kosnik <bkoz@redhat.com> wrote:

> Needs some more work, here's a rough draft.

The one I've seen most often other than including cstddef is due to linker
options starting with -- (eg. --export-dynamic, --no-undefined) now being
errors. Previously they were just silently ignored.

The fix of course is to prepend "-Wl," to these flags.

http://gcc.gnu.org/PR46410
Matthias Klose - March 17, 2011, 1:59 p.m.
On 17.03.2011 07:51, Benjamin Kosnik wrote:
> 
> Needs some more work, here's a rough draft.
> 
> -benjamin

+ <p>As a workaround, remove <code>-Werror</code> until the new warnings
+ are fixed, or for conversion warnings
+ add <code>-Wno-unused-but-set-variable</code>
+ or <code>-Wno-unused-but-set-parameter</code>.
+ </p>

what about recommending keeping -Werror and adding
-Wno-error=unused-but-set-variable or -Wno-error=unused-but-set-parameter?
Then the warnings remain, but don't cause an error.

  Matthias

Patch

Index: htdocs/gcc-4.6/porting_to.html
===================================================================
RCS file: htdocs/gcc-4.6/porting_to.html
diff -N htdocs/gcc-4.6/porting_to.html
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- htdocs/gcc-4.6/porting_to.html	17 Mar 2011 06:47:42 -0000
***************
*** 0 ****
--- 1,167 ----
+ <html>
+ 
+ <head>
+ <title>GCC 4.6 Release Series &mdash; Porting to the New Tools</title>
+ </head>
+ 
+ <body>
+ <h1>GCC 4.6 Release Series<br />Porting to the New Tools</h1>
+ 
+ <p>
+ The GCC 4.6 release series differs from previous GCC releases in more
+ than the usual list
+ of <a href="http://gcc.gnu.org/gcc-4.6/changes.html">new
+ features</a>. Some of these changes are a result of bug fixing, and
+ some old behaviors have been intentionally changed in order to support
+ new standards, or relaxed in standards-conforming ways to facilitate
+ compilation or runtime performance. Some of these changes are not
+ visible to the naked eye, and will not cause problems when updating
+ from older GCC versions.
+ </p>
+ 
+ <p>
+ However, some of these changes are visible, and can cause grief to
+ users porting to GCC 4.6. This document is an effort to identify major
+ issues and provide clear solutions in a quick and easily-searched
+ manner. Additions and suggestions for improvement are welcome.
+ </p>
+ 
+ <h3>C language issues</h3>
+ 
+ <h4>New warnings for unused variables and parameters</h4>
+ 
+ <p>
+ The behavior of <code>-Wall</code> has changed and now includes the
+ new warning flags <code>-Wunused-but-set-variable</code> and
+ (with <code>-Wall
+ -Wextra</code>) <code>-Wunused-but-set-parameter</code>. This may
+ result in new warnings in code that compiled cleanly with previous
+ versions of GCC.
+ </p>
+ 
+ <p>
+ For example,
+ </p>
+ 
+ <pre>
+   void fn (void)
+   {
+     int foo;
+     foo = bar ();  /* foo is never used.  */
+   }
+ </pre>
+ 
+ <p>
+ Gives the following diagnostic:
+ </p>
+ 
+ <pre>
+ warning: variable ‘foo’ set but not used [-Wunused-but-set-variable]
+ </pre>
+ 
+ <p> Although these warnings will
+ not result in compilation failure, often <code>-Wall</code> is used in
+ conjunction with <code>-Werror</code> and as a result, new warnings
+ are turned into new errors.
+ </p>
+ 
+ <p>
+ To fix, first see if the unused variable or parameter can be removed
+ without changing the result or logic of the surrounding code. If not,
+ annoate it with <code>__attribute__((__unused__))</code>
+ </p>
+ 
+ <p>As a workaround, remove <code>-Werror</code> until the new warnings
+ are fixed, or for conversion warnings
+ add <code>-Wno-unused-but-set-variable</code>
+ or <code>-Wno-unused-but-set-parameter</code>.
+ </p>
+ 
+ <h4>Strict overflow warnings</h4>
+ 
+ <p>
+ Using the <code>-Wstrict-overflow</code> flag
+ with <code>-Werror</code> and optmization flags above <code>-O2</code>
+ may result in compile errors when using glibc optimizations
+ for <code>strcmp</code>.
+ </p>
+ 
+ <p>
+ For example,
+ </p>
+ 
+ <pre>
+ #include <string.h>
+ void do_rm_rf (const char *p) { if (strcmp (p, "/") == 0) return; }
+ </pre>
+ 
+ <p>
+ Results in the following diagnostic:
+ </p>
+ 
+ <pre>
+ error: assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C1 +- C2 [-Werror=strict-overflow]
+ </pre>
+ 
+ <p>
+ To work around this, use </code>-D__NO_STRING_INLINES</code>.
+ </p>
+ 
+ <h3>C++ language issues</h3>
+ 
+ <h4>Header dependency changes</h4>
+ 
+ <p>
+ Many of the standard C++ library include files have been edited to no
+ longer include &lt;cstddef&gt; to get <code>namespace std</code>
+ -scoped versions of <code>size_t</code> and <code>ptrdiff_t</code>. 
+ </p>
+ 
+ <p>
+ As such, C++ programs that used the macros <code>NULL</code>
+ or <code>offsetof</code> without including &lt;cstddef&gt; will no
+ longer compile. The diagnostic produced is similar to:
+ </p>
+ 
+ <pre>
+ error: 'ptrdiff_t' does not name a type
+ </pre>
+ 
+ <pre>
+ error: 'size_t' has not been declared
+ </pre>
+ 
+ <pre>
+ error: 'NULL' was not declared in this scope
+ </pre>
+ 
+ <pre>
+ error: there are no arguments to 'offsetof' that depend on a template
+ parameter, so a declaration of 'offsetof' must be available
+ </pre>
+ 
+ <p>
+ Fixing this issue is easy, just include &lt;cstddef&gt;.
+ </p>
+ 
+ <h3>Java issues</h3>
+ 
+ <h3>Links</h3>
+ 
+ <p>
+ Jakub Jelinek, <a href="http://lists.fedoraproject.org/pipermail/devel/2011-February/148523.html">GCC 4.6 related common package rebuild failures (was Re: mass rebuild status)</a>
+ </p>
+ 
+ <p>
+ Matthias Klose, <a href="http://lists.debian.org/debian-devel-announce/2011/02/msg00012.html">prepare to fix build failures with new GCC versions</a>
+ </p>
+ 
+ <p>
+ Jim Meyering, <a href="http://lists.fedoraproject.org/pipermail/devel/2011-March/149355.html">gcc-4.6.0-0.12.fc15.x86_64 breaks strcmp?</a>
+ </p>
+ <!-- ==================================================================== -->
+ 
+ </body>
+ </html>
+   
+