NetBSD Problem Report #40695

From www@NetBSD.org  Thu Feb 19 21:57:59 2009
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id C05E563BB35
	for <gnats-bugs@gnats.netbsd.org>; Thu, 19 Feb 2009 21:57:59 +0000 (UTC)
Message-Id: <20090219215759.8982363B8C3@narn.NetBSD.org>
Date: Thu, 19 Feb 2009 21:57:59 +0000 (UTC)
From: jkunz@NetBSD.org
Reply-To: jkunz@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: C99 violation: Macro NAN in /usr/include/math.h in not constant.
X-Send-Pr-Version: www-1.0

>Number:         40695
>Category:       standards
>Synopsis:       C99 violation: Macro NAN in /usr/include/math.h in not constant.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    standards-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 19 22:00:00 +0000 2009
>Closed-Date:    Sat Sep 22 14:04:28 +0000 2018
>Last-Modified:  Sat Sep 22 14:04:28 +0000 2018
>Originator:     Jochen Kunz
>Release:        5.0_RC1
>Organization:
The NetBSD Foundation
>Environment:
NetBSD MissSophie 5.0_RC1 NetBSD 5.0_RC1 (MissSophie) #19: Thu Feb 12 22:24:31 CET 2009  jkunz@MissSophie:/usr/src/build/MissSophie i386
>Description:
The macro NAN (Not A Number) in /usr/include/math.h expands to a variable and is not constant.

C99 (http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf), section 7.12.5 "Mathematics <math.h>", page 213 requires:

The macro
        NAN
is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a quiet NaN.


>How-To-Repeat:
The folowing program fails to compile:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

double f1 = NAN;

int
main(int argc, char** argv) {
	printf( "NAN: %f\n", f1);
	exit( EXIT_SUCCESS);
}
>Fix:

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: standards/40695: C99 violation: Macro NAN in /usr/include/math.h in not constant.
Date: Thu, 19 Feb 2009 23:10:44 +0100

 --AhhlLboLdkugWU4S
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline

 This should fix it (not tested yet), plus a warn reference for __nanf.

 Martin

 --AhhlLboLdkugWU4S
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=patch

 Index: math.h
 ===================================================================
 RCS file: /cvsroot/src/include/math.h,v
 retrieving revision 1.47
 diff -c -u -r1.47 math.h
 --- math.h	25 Apr 2008 21:20:57 -0000	1.47
 +++ math.h	19 Feb 2009 22:09:41 -0000
 @@ -87,8 +87,12 @@

  /* 7.12#5 NAN: a quiet NaN, if supported */
  #ifdef __HAVE_NANF
 +#if __GNUC_PREREQ__(3,3)
 +#define	NAN	__builtin_nanf("")
 +#else
  extern const union __float_u __nanf;
  #define	NAN		__nanf.__val
 +#endif
  #endif /* __HAVE_NANF */

  /* 7.12#6 number classification macros */

 --AhhlLboLdkugWU4S--

From: Martin Husemann <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/40695 CVS commit: src
Date: Sun, 22 Feb 2009 01:34:02 +0000 (UTC)

 Module Name:	src
 Committed By:	martin
 Date:		Sun Feb 22 01:34:02 UTC 2009

 Modified Files:
 	src/include: math.h
 	src/lib/libc/arch/alpha/gen: nanf.c
 	src/lib/libc/arch/arm/gen: nanf.c
 	src/lib/libc/arch/hppa/gen: nanf.c
 	src/lib/libc/arch/i386/gen: nanf.c
 	src/lib/libc/arch/m68k/gen: nanf.c
 	src/lib/libc/arch/mips/gen: nanf.c
 	src/lib/libc/arch/powerpc/gen: nanf.c
 	src/lib/libc/arch/powerpc64/gen: nanf.c
 	src/lib/libc/arch/sh3/gen: nanf.c
 	src/lib/libc/arch/sparc/gen: nanf.c
 	src/lib/libc/arch/sparc64/gen: nanf.c
 	src/lib/libc/arch/x86_64/gen: nanf.c

 Log Message:
 Make NAN a compile time constant (with help from the compiler). Suggested
 by krister. Fixes PR 40695.
 Make references to the old construct (which we can't remove for binary
 compatibility reasons) emit a linker warning.


 To generate a diff of this commit:
 cvs rdiff -r1.47 -r1.48 src/include/math.h
 cvs rdiff -r1.4 -r1.5 src/lib/libc/arch/alpha/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/arm/gen/nanf.c
 cvs rdiff -r1.1 -r1.2 src/lib/libc/arch/hppa/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/i386/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/m68k/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/mips/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/powerpc/gen/nanf.c
 cvs rdiff -r1.1 -r1.2 src/lib/libc/arch/powerpc64/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/sh3/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/sparc/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/sparc64/gen/nanf.c
 cvs rdiff -r1.3 -r1.4 src/lib/libc/arch/x86_64/gen/nanf.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Alan Barrett <apb@cequrux.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: PR/40695 CVS commit: src
Date: Sun, 22 Feb 2009 12:51:11 +0200

 On Sun, 22 Feb 2009, Martin Husemann wrote:
 >  Make NAN a compile time constant (with help from the compiler). Suggested
 >  by krister. Fixes PR 40695.
 >  Make references to the old construct (which we can't remove for binary
 >  compatibility reasons) emit a linker warning.

 Who is helped by the linker warning?  Presumably people running old code
 don't care whether or not NAN was a compile time constant, as long as it
 works.

 --apb (Alan Barrett)

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: standards-manager@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org, jkunz@NetBSD.org
Subject: Re: PR/40695 CVS commit: src
Date: Sun, 22 Feb 2009 12:32:01 +0100

 On Sun, Feb 22, 2009 at 11:00:05AM +0000, Alan Barrett wrote:
 >  Who is helped by the linker warning?  Presumably people running old code
 >  don't care whether or not NAN was a compile time constant, as long as it
 >  works.

 You don't get the warning unless you re-link your app - in which case it would
 be better to recompile and the warning would be gone. And it's only a warning
 anyway.

 The warning helps us to remember adding a similar construct for ppc or others
 later. I don't realy care about it - if others feel it should go away, that's
 fine with me.

 Martin

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: jkunz@NetBSD.org
Subject: Re: PR/40695 CVS commit: src
Date: Sun, 22 Feb 2009 12:33:21 +0100

 On Sun, Feb 22, 2009 at 12:32:01PM +0100, Martin Husemann wrote:
 > The warning helps us to remember adding a similar construct for ppc or others
 > later.

 Actually turning the test case from this PR into a regression test would
 serve the same purpose and should be done anyway.

 Martin

From: Alan Barrett <apb@cequrux.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: PR/40695 CVS commit: src
Date: Sun, 22 Feb 2009 15:03:21 +0200

 On Sun, 22 Feb 2009, Martin Husemann wrote:
 > >  Who is helped by the linker warning?  Presumably people running old code
 > >  don't care whether or not NAN was a compile time constant, as long as it
 > >  works.
 > 
 > You don't get the warning unless you re-link your app - in which case
 > it would be better to recompile and the warning would be gone. And
 > it's only a warning anyway.

 That makes sense; thanks.  I had incorrectly thought that linker
 warnings were also displayed when shared libraries were loaded at run
 time.

 --apb (Alan Barrett)

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sat, 22 Sep 2018 14:04:28 +0000
State-Changed-Why:
Fixed by martin and krister a while back. THanks for the report!


>Unformatted:
 gdt@ir.bbn.com

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.