NetBSD Problem Report #56402

From www@netbsd.org  Tue Sep 14 23:34:30 2021
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 9832B1A921F
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 14 Sep 2021 23:34:30 +0000 (UTC)
Message-Id: <20210914233429.1BA7A1A9239@mollari.NetBSD.org>
Date: Tue, 14 Sep 2021 23:34:29 +0000 (UTC)
From: k0ga@shike2.com
Reply-To: k0ga@shike2.com
To: gnats-bugs@NetBSD.org
Subject: Definition of lldiv_t with ANSI_SOURCE and POSIX_SOURCE
X-Send-Pr-Version: www-1.0

>Number:         56402
>Category:       standards
>Synopsis:       Definition of lldiv_t with ANSI_SOURCE and POSIX_SOURCE
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    standards-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 14 23:35:00 +0000 2021
>Closed-Date:    Fri Oct 11 19:08:31 +0000 2024
>Last-Modified:  Fri Oct 11 19:08:31 +0000 2024
>Originator:     Roberto E. Vargas Caballero
>Release:        NetBSD 9.1
>Organization:
>Environment:
NetBSD odin 9.1 NetBSD 9.1 (GENERIC) #0: Sun Oct 18 19:24:30 UTC 2020  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
When a source file including stdlib.h is compiled with the flags -_ANSI_SOURCE and _POSIX_SOURCE the compilation fails with the error:

/usr/include/stdlib.h:227:1: error: unknown type name 'lldiv_t'; did you mean 'ldiv_t'?

Looking in the /usr/include/stdlib.h we find:


#if !defined(_ANSI_SOURCE) && \
    (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
     (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE))
typedef struct {
        /* LONGLONG */
        long long int quot;     /* quotient */
        /* LONGLONG */
        long long int rem;      /* remainder */
} lldiv_t;
#endif


...

#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
    defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L

/* LONGLONG */
long long int   atoll(const char *);
/* LONGLONG */
long long int   llabs(long long int);
/* LONGLONG */
lldiv_t         lldiv(long long int, long long int);
/* LONGLONG */
long long int   strtoll(const char * __restrict, char ** __restrict, int);
/* LONGLONG */
unsigned long long int
                strtoull(const char * __restrict, char ** __restrict, int);
float           strtof(const char * __restrict, char ** __restrict);
long double     strtold(const char * __restrict, char ** __restrict);
#endif


We can see that the definition of lldiv_t is enabled only when !defined(_ANSI_SOURCE) but lldiv() is declared regardless of the value of _ANSI_SOURCE. The same check should be used in both places.

>How-To-Repeat:
$ cat <<EOF > f.c
#define _ANSI_SOURCE
#define _POSIX_SOURCE

#include <stdlib.h>

int
main(void)
{
        return 0;
}
EOF
$ cc f.c
In file included from f.c:4:0:
/usr/include/stdlib.h:227:1: error: unknown type name 'lldiv_t'; did you mean 'ldiv_t'?
>Fix:
--- /usr/include/stdlib.h       2020-10-18 21:24:30.000000000 +0200
+++ /usr/include/stdlib.h.new 2021-09-15 01:02:48.399518921 +0200
/*
 * ISO C99
 */
-#if defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
-    defined(_NETBSD_SOURCE) || (__cplusplus - 0) >= 201103L
+#if !defined(_ANSI_SOURCE) && \
+    (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
+     (__cplusplus - 0) >= 201103L || defined(_NETBSD_SOURCE))

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Mon, 09 Sep 2024 15:15:48 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-10 and pullup-9


From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56402 CVS commit: src/include
Date: Mon, 9 Sep 2024 15:15:24 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Mon Sep  9 15:15:24 UTC 2024

 Modified Files:
 	src/include: stdlib.h

 Log Message:
 stdlib.h: Use same test for def. of lldiv_t as for decl. of lldiv(3).

 The !_ANSI_SOURCE conditional was a leftover from before we had
 _NETBSD_SOURCE in sys/featuretest.h already defined conditionally on
 !_ANSI_SOURCE.

 So just nix the !_ANSI_SOURCE part -- and while here, reorder and
 reformat the conditional around lldiv_t so it matches the conditional
 around lldiv(3) byte-for-byte, just to make it more obvious.

 PR standards/56402: Definition of lldiv_t with ANSI_SOURCE and
 POSIX_SOURCE


 To generate a diff of this commit:
 cvs rdiff -u -r1.125 -r1.126 src/include/stdlib.h

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

State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Fri, 11 Oct 2024 18:15:39 +0000
State-Changed-Why:
pullup-10 #951 https://releng.netbsd.org/cgi-bin/req-10.cgi?show=951
not worth risk of build breakage for pullup-9


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56402 CVS commit: [netbsd-10] src/include
Date: Fri, 11 Oct 2024 19:03:24 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Oct 11 19:03:24 UTC 2024

 Modified Files:
 	src/include [netbsd-10]: stdlib.h

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #951):

 	include/stdlib.h: revision 1.126

 stdlib.h: Use same test for def. of lldiv_t as for decl. of lldiv(3).

 The !_ANSI_SOURCE conditional was a leftover from before we had
 _NETBSD_SOURCE in sys/featuretest.h already defined conditionally on
 !_ANSI_SOURCE.

 So just nix the !_ANSI_SOURCE part -- and while here, reorder and
 reformat the conditional around lldiv_t so it matches the conditional
 around lldiv(3) byte-for-byte, just to make it more obvious.

 PR standards/56402: Definition of lldiv_t with ANSI_SOURCE and
 POSIX_SOURCE


 To generate a diff of this commit:
 cvs rdiff -u -r1.125 -r1.125.2.1 src/include/stdlib.h

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

State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Fri, 11 Oct 2024 19:08:31 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 10, risk not worth it for 9


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.