220 29209 <58137954.60906@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: pragma once
Date: Fri, 28 Oct 2016 12:14:12 -0400
Lines: 52
Approved: news@gmane.org
Message-ID: <58137954.60906@gmail.com>
References: <CAGz9X0c=CNLVEGgJ7=GJ2W+7fsvN7h+tbiFyf5Cx3aab0Xb=rQ@mail.gmail.com>
 <ffa0cf8c-25a4-49fe-9e99-dcce452b8dd6@isocpp.org>
 <2c278558-0dbc-4568-9b6b-7f159c94707e@isocpp.org>
 <4610802.tOzma7na2T@tjmaciei-mobl1>
 <fefab967-9db3-7204-a2d0-b9984ca5e8b4@gmail.com>
 <CAGg_6+OFUqxzy-3YErVKS0-4dU2TxLrJjev9TGWKOA1v8Lnp3g@mail.gmail.com>
 <CAEhD+6BXvsZ+NJgnbX3yiGQWQRzWODYz-NfG8p3U++Au90cKjA@mail.gmail.com>
 <58135E5F.7000107@gmail.com> <393e093b-6fe3-6c30-0d91-12a3bae68a95@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: blaine.gmane.org 1477671285 16734 195.159.176.226 (28 Oct 2016 16:14:45 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 28 Oct 2016 16:14:45 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.1.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBYPSZXAAKGQE75PODRQ@isocpp.org Fri Oct 28 18:14:39 2016
Return-path: <std-proposals+bncBC37LBFWUIFBBYPSZXAAKGQE75PODRQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f197.google.com ([209.85.161.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBYPSZXAAKGQE75PODRQ@isocpp.org>)
	id 1c09nT-0001eH-I9
	for gclcip-std-proposals@m.gmane.org; Fri, 28 Oct 2016 18:14:23 +0200
Original-Received: by mail-yw0-f197.google.com with SMTP id w3sf97370111ywg.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 28 Oct 2016 09:14:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:newsgroups:from:message-id:date:user-agent
         :mime-version:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=PYQ+Z5YnieKUEVfZzf2WNYL/IOaNR+M0cxPZez69Te4=;
        b=tVZHJ382lMXPFRM/1XfkWLhTx9Io4Gzq8Cn9yGmSesdxuSlUE5kTew20GSGRZh9wGt
         NLQX89eOXChEltGuClviCsUlfz8bhvXf1mNdIkyeBUJEHsczNfCVG0cL5OcWwnlrlCXc
         8du+bLZEFRxikOKDrsEw2ZL60vNlbRQb1QtY16+qs+DiuIRaQTTqTxQvtqFGL3O3aVZ2
         lFkEpwd2bXZPRWcEWbqxbwqLDeHNKurFYx1CqkkYajEXIGmdYuho3PRi5C8Tfl8AdQOF
         0pH69j7lUSTkuRIiSEceIhmdFb+yF3CjEHyAAEPovwYMRo7AvRige3biCaQnvBfXQ3Tv
         UPPw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:subject:to:references:newsgroups:from:message-id
         :date:user-agent:mime-version:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=PYQ+Z5YnieKUEVfZzf2WNYL/IOaNR+M0cxPZez69Te4=;
        b=OzItL12OK4q7zI7aHyi3ordtfLIwGb+45Quqajoa61Lb6Q3D6axRhEBj9uzGj3YEGK
         +fwRGAytUH0M1Hy+8dmFl+ufWz4D8LqDs2qKHxjUSJUJFwL0jQGkwzftb5ql2ci7rVZD
         YcVicg2fimMs2xU5VfDw7WBUgQhTwFYCQz0TooRa9wT0K3SVu3toKnD5h96wreqNDQ8G
         A39G04/pBLCyFTou8Yg2VBz9qZeQjNlYV5oLFSFtnH7TF1jtVUSnZGpUTh3D1k6dxVGN
         0GnWlU2QGkGER94BQwBZMd8agmZEd3TLCy/ORygCeB5xcFH8o2w6bBI073/3x9jNqsvL
         4LIg==
X-Gm-Message-State: ABUngvfTSLDW3aW5/gcMX9v6C65L7yMFakXcRkyFJzqM10INfY62ReOhTi0r1T16UHYCbw==
X-Received: by 10.129.95.137 with SMTP id t131mr4127960ywb.41.1477671265781;
        Fri, 28 Oct 2016 09:14:25 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.53.52 with SMTP id o49ls7220666otc.18.gmail; Fri, 28 Oct
 2016 09:14:25 -0700 (PDT)
X-Received: by 10.176.65.167 with SMTP id 36mr12856826uap.75.1477671265063;
        Fri, 28 Oct 2016 09:14:25 -0700 (PDT)
Original-Received: from mail-qt0-x233.google.com (mail-qt0-x233.google.com. [2607:f8b0:400d:c0d::233])
        by mx.google.com with ESMTPS id k6si6572447uak.143.2016.10.28.09.14.25
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 28 Oct 2016 09:14:25 -0700 (PDT)
Received-SPF: pass (google.com: domain of mwoehlke.floss@gmail.com designates 2607:f8b0:400d:c0d::233 as permitted sender) client-ip=2607:f8b0:400d:c0d::233;
Original-Received: by mail-qt0-x233.google.com with SMTP id p16so39042111qta.0
        for <std-proposals@isocpp.org>; Fri, 28 Oct 2016 09:14:25 -0700 (PDT)
X-Received: by 10.237.57.98 with SMTP id l89mr11234655qte.146.1477671264537;
        Fri, 28 Oct 2016 09:14:24 -0700 (PDT)
Original-Received: from [192.168.1.173] (tripoint.kitware.com. [66.194.253.20])
        by smtp.googlemail.com with ESMTPSA id 16sm6566286qtf.36.2016.10.28.09.14.24
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 28 Oct 2016 09:14:24 -0700 (PDT)
Original-Newsgroups: gmane.comp.lang.c++.isocpp.proposals
In-Reply-To: <393e093b-6fe3-6c30-0d91-12a3bae68a95@gmail.com>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 mwoehlke.floss@gmail.com designates 2607:f8b0:400d:c0d::233 as permitted
 sender) smtp.mailfrom=mwoehlke.floss@gmail.com;       dmarc=pass (p=NONE
 dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:29209
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29209>

On 2016-10-28 11:54, Andrey Semashev wrote:
> On 10/28/16 17:19, Matthew Woehlke wrote:
>> On 2016-10-27 19:06, Andrey Semashev wrote:
>>> I think a proposal similar to the previously mentioned "#once
>>> guard_phrase" has more potential. It does give the user a way to
>>> indicate file equivalence (through the guard name) and also is
>>> arguably less expensive than computing a hash value.
>>
>> Perhaps more importantly, it doesn't require parsing the file in two
>> passes. Since it is ill-formed for `#once` to appear after meaningful
>> content, if the compiler is in doubt it can just process the file
>> normally until `#once`, and then (potentially) stop.
> 
> I think #once shouldn't be required to appear before any (meaningful?)
> content. The common practice is to include a config header that detects
> the features supported by compiler (that would include support for
> #once) and then do any other stuff. For instance, in Boost "#pragma
> once" is often used like this:
> 
>   #include <boost/config.hpp>
> 
>   #if defined(BOOST_HAS_PRAGMA_ONCE)
>   #pragma once
>   #endif

You're *partly* right. Really, it *should* not follow any content that
could potentially change the meaning of the program depending on whether
the header is processed more than once. In your example, assuming that
<boost/config.hpp> is also guarded, you'd be okay.

The trouble is you lose the optimization chance to not read the file at
all the second time. However, it is plausible that compilers could
detect if a second inclusion, even in a case like above, would be a
no-op as a matter of QoI.

Since this would also allow a better fix for ensuring that version
checks happen (when only one header has a version check, e.g. the above
<boost/config.hpp>), I think I am convinced :-). Thanks!

(Of course, this means any content before `#once` is parsed twice...
which may even be a good thing in some corner cases! Anyway, we still an
extra parsing pass to compute a hash.)

-- 
Matthew

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/58137954.60906%40gmail.com.

.
