Fix problem with GCC 4.9.1 in string/tester.c

Message ID 54D725BC.8050604@web.de
State Rejected
Headers

Commit Message

Leonhard Holz Feb. 8, 2015, 9 a.m. UTC
  tester.c does not compile on my Xubuntu 14.10 with GCC Ubuntu 4.9.1-16ubuntu6. 
This patch fixes it. Maybe the Ubuntu folks did backport something.
  

Comments

Andreas Schwab Feb. 8, 2015, 9:17 a.m. UTC | #1
GCC 4.9 doesn't implement -Wmemset-transposed-args.

Andreas.
  
Ondrej Bilka Feb. 8, 2015, 10:35 a.m. UTC | #2
On Sun, Feb 08, 2015 at 10:17:45AM +0100, Andreas Schwab wrote:
> GCC 4.9 doesn't implement -Wmemset-transposed-args.
> 
But in debian and ubuntu derivate it does. I used same patch but because
Joseph complained that it causes yet another nonsense warning I reverted
that.
  
Carlos O'Donell Feb. 9, 2015, 8:29 p.m. UTC | #3
On 02/08/2015 04:00 AM, Leonhard Holz wrote:
> tester.c does not compile on my Xubuntu 14.10 with GCC Ubuntu 4.9.1-16ubuntu6. This patch fixes it. Maybe the Ubuntu folks did backport something.
> 
> diff --git a/string/tester.c b/string/tester.c
> index f957ed2..445b427 100644
> --- a/string/tester.c
> +++ b/string/tester.c
> @@ -1305,9 +1305,9 @@ test_memset (void)
>    equal(one, "axxxefgh", 2);           /* Basic test. */
> 
>    DIAG_PUSH_NEEDS_COMMENT;
> -#if __GNUC_PREREQ (5, 0)
> -  /* GCC 5.0 warns about a zero-length memset because the arguments to memset
> -     may be in the wrong order.  But we really want to test this.  */
> +#if __GNUC_PREREQ (5, 0) || __GNUC_PREREQ (4, 9)
> +  /* GCC 5.0 / 4.9 warns about a zero-length memset because the arguments to
> +     memset may be in the wrong order.  But we really want to test this.  */
>    DIAG_IGNORE_NEEDS_COMMENT (5.0, "-Wmemset-transposed-args")
>  #endif
>    (void) memset(one+2, 'y', 0);

Leonhard,

As Andreas states, FSF GCC 4.9 doesn't actually have this problem. Bare GCC 
version references are always for the canonical upstream version.

So what is the correct fix?

Good question.

Joseph,

You and I have talked before about testing for compiler features rather
than version.

Do you think the correct fix is to test for the warning at configure time,
set HAVE_WARN_MEMSET_TRANSPOSED_ARGS in config.h, and then use that to
conditionalize the DIAG_* statements?

I don't see any other way to have this work.

The configure check would need a detailed comment about exactly which
compiler has this feature backported that's causing problems.

Thankfully this is just a test and not an installed header.

Cheers,
Carlos.
  
Joseph Myers Feb. 9, 2015, 11:34 p.m. UTC | #4
On Mon, 9 Feb 2015, Carlos O'Donell wrote:

> Do you think the correct fix is to test for the warning at configure time,
> set HAVE_WARN_MEMSET_TRANSPOSED_ARGS in config.h, and then use that to
> conditionalize the DIAG_* statements?

Yes.

> I don't see any other way to have this work.

You could disable -Wpragmas, but I don't think that would be a good idea.
  

Patch

diff --git a/string/tester.c b/string/tester.c
index f957ed2..445b427 100644
--- a/string/tester.c
+++ b/string/tester.c
@@ -1305,9 +1305,9 @@  test_memset (void)
    equal(one, "axxxefgh", 2);           /* Basic test. */

    DIAG_PUSH_NEEDS_COMMENT;
-#if __GNUC_PREREQ (5, 0)
-  /* GCC 5.0 warns about a zero-length memset because the arguments to memset
-     may be in the wrong order.  But we really want to test this.  */
+#if __GNUC_PREREQ (5, 0) || __GNUC_PREREQ (4, 9)
+  /* GCC 5.0 / 4.9 warns about a zero-length memset because the arguments to
+     memset may be in the wrong order.  But we really want to test this.  */
    DIAG_IGNORE_NEEDS_COMMENT (5.0, "-Wmemset-transposed-args")
  #endif
    (void) memset(one+2, 'y', 0);