From patchwork Thu Mar 20 01:17:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 183 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (caibbdcaabja.dreamhost.com [208.113.200.190]) by wilcox.dreamhost.com (Postfix) with ESMTP id B79DB3600CD for ; Wed, 19 Mar 2014 18:17:43 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14307373) id 5852E62CA030E; Wed, 19 Mar 2014 18:17:43 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id 3090762C2D9FF for ; Wed, 19 Mar 2014 18:17:43 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type; q=dns; s=default; b= tml9Cq25IgZodZp2/Pg9dAJeGZ46bZ4GPG3kNcheI4BEWajmzQUv3W2+fg2gw3rl 2q17BWJOo8mntWMqowA508AATp00SlHrhax/8v5du+yZGVEbUNPJVVtcUrUVmqEW Rf7nbbOca/YyjuQU3qSzVc1Ogq8+7bW5IrPZuan4LBc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type; s=default; bh=4JfJ s0HovqGaD7cvtYYTEb5mil0=; b=Uy59sRO2eFy1pKMQJ7lFhY4ZKdv6TMu5b9ON AaY95tivjjXDTrjFUYg2abFuagw6YFLMhCtgNPnp+R8SMr9kV0FK4p8q2zUW9lcG BzH3H58YbWBdg7iv/Xxu+ytWWAcP6NSr85bQhXexTARjvrab+rhsuPD36ifVsOA8 MybL41k= Received: (qmail 3812 invoked by alias); 20 Mar 2014 01:17:40 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 3798 invoked by uid 89); 20 Mar 2014 01:17:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: smtp.cs.ucla.edu Message-ID: <532A41AA.9060208@cs.ucla.edu> Date: Wed, 19 Mar 2014 18:17:30 -0700 From: Paul Eggert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: "Joseph S. Myers" CC: Mike Frysinger , libc-alpha@sourceware.org Subject: Re: [RFC] Make _FILE_OFFSET_BITS=64 default. References: <1393521776-1102-1-git-send-email-reprofy@etersoft.ru> <3427802.83HSs9lgGH@vapier> <532956D4.5020804@cs.ucla.edu> <9842031.PgVxWc0IpI@vapier> <5329DC42.2000409@cs.ucla.edu> In-Reply-To: X-DH-Original-To: glibc@patchwork.siddhesh.in Joseph S. Myers wrote: > I certainly don't think they should be overriding _Static_assert provided by GCC (>= 4.6) Good point, thanks. Revised patches attached. > I don't think the installed glibc headers should be providing _Static_assert It's what FreeBSD does, and applications seem to be doing fine there. So there's good precedent, it's not risky, and it would improve compatibility with FreeBSD. > arguably assert.h should try to do something for the case > of _ISOC11_SOURCE, non-C11 compiler That wouldn't support one of the main attractions of _Static_assert, namely that it works even when isn't included. Application writers will prefer this feature, and defining _Static_assert in cdefs.h gets us close enough to this goal to be reasonably useful in apps compiled with pre-C11 compilers. > generally that applies to any compiler possibly providing > _Static_assert outside C11 mode - the library shouldn't get in the way of > the user using the compiler feature In general that's a good principle, but here there's not much to get in the way of, as the glibc substitute does the job even when it takes over from Clang etc. If there's consensus I could add the usual forest of #ifs so as to not #define _Static_assert in non-GCC pre-C11 compilers where _Static_assert is known to work, but that's not what we've done in similar situations elsewhere in glibc, and there is some virtue in simplicity. From 45c96ea279e95aa499856f9062f743665fd564ee Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 19 Mar 2014 10:59:31 -0700 Subject: [PATCH 1/2] Approximate _Static_assert for pre-C11 compilers. * misc/sys/cdefs.h (_Static_assert) [__STDC_VERSION__ < 201112L]: New macro, for convenience with pre-C11 compilers. --- ChangeLog | 6 ++++++ misc/sys/cdefs.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index f48f6bb..3d4c88d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-03-19 Paul Eggert + + Approximate _Static_assert for pre-C11 compilers. + * misc/sys/cdefs.h (_Static_assert) [__STDC_VERSION__ < 201112L]: + New macro, for convenience with pre-C11 compilers. + 2014-03-19 Joseph Myers * math/libm-test.inc (fdim_test): Use ALL_RM_TEST. diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 4d958ea..9402520 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -382,6 +382,13 @@ # define __glibc_likely(cond) (cond) #endif +#if ! (defined _Static_assert \ + || (defined __STDC_VERSION__ && 201112L <= __STDC_VERSION__) \ + || (__GNUC_PREREQ (4, 6) && !defined __STRICT_ANSI__)) +# define _Static_assert(e, s) extern int (*__glibc_Static_assert (void)) \ + [sizeof (struct { unsigned int _Static_assert_failure: (e) ? 1 : -1; })] +#endif + #include #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH