220 29467 <634b6222-d3e2-828b-75ec-f9da31b0493a@honermann.net> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Tom Honermann <tom@honermann.net>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allowing string literals to match `char...` packs
 in templates
Date: Fri, 18 Nov 2016 11:19:01 -0500
Lines: 84
Approved: news@gmane.org
Message-ID: <634b6222-d3e2-828b-75ec-f9da31b0493a@honermann.net>
References: <9de07b5f-f870-4a02-882f-54f9fdd12ffd@isocpp.org>
 <CAEddoJZf-Y9D90ZePLoMv_HcFeCJz+FC25WRVdWZjbsrrS4FEQ@mail.gmail.com>
 <cb9de829-bc1b-f9b7-6864-6b5ad0c4b5af@honermann.net>
 <7366336.xLjCtBizz3@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1479485960 24021 195.159.176.226 (18 Nov 2016 16:19:20 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 18 Nov 2016 16:19:20 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101
 Thunderbird/45.4.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDBNXSHG6UDBBBGUXTAQKGQEEHQ3TYY@isocpp.org Fri Nov 18 17:19:15 2016
Return-path: <std-proposals+bncBDBNXSHG6UDBBBGUXTAQKGQEEHQ3TYY@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+bncBDBNXSHG6UDBBBGUXTAQKGQEEHQ3TYY@isocpp.org>)
	id 1c7lsg-0005bl-Js
	for gclcip-std-proposals@m.gmane.org; Fri, 18 Nov 2016 17:19:14 +0100
Original-Received: by mail-yw0-f197.google.com with SMTP id d187sf497039951ywe.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 18 Nov 2016 08:19:18 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:content-transfer-encoding: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=EERofbta4eZPj+FIlrq8jiUlLJ8fgw3tZGI1BcH07QU=;
        b=lcgodYk7SizC+FaahaKEm1HsMQN7qYRqPskQLAztrWG5lRIAd0EpbIda/6Xzh4tLwY
         QRiznoch+loFc4VJQGlv0fjVcAab14yWepMwjlbeS46uXKJvPc4g2FMAo25ynSAnSkGf
         QgkjAabRj0IhJH3jLnIZER59Fx1ZIiGQPzF4P5W2ISgYRPCJZawUx2TXBPweLIiGGTY/
         tN9alQ191bPAum2SjWbiqTYU8niwd7iELXQ5MBrYtCwdh5dO8PZNELTd2NpggbIv9zE3
         mseYs3KgkNg96/UP3enskDCkNqvp9Ir2UET5SzOJGUEE1SlZwgMMdWRyxhIpSh9HeetA
      
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:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-transfer-encoding
         :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=EERofbta4eZPj+FIlrq8jiUlLJ8fgw3tZGI1BcH07QU=;
        b=ioF1zbU3UXVU3Y2iiYVhi0cQFgoKhHXRWW6tuVk7c/bxn/rqUOawJSpYLhConCEjQJ
         YVHOWsDHhUCeKmdesnTigRIgQEorxXQTEjo86peErmlOuTeC+J8L+SuEPppoSJ8XnrUJ
         lAOhEKNnrY2JSNkKzqtBuwhFCkKall0te0AvfgVuu6DWyKshU9kvaL7PJqRAhFO/oRqn
         BaEghewIYkGxrfu6tO37+1G1GP3V7FjpqdT/nZU/YBXpGeAfdJaxyGU+v85paC4JOJVf
         AfrWy5XGRF/+kY9ISVXmv/wedfFr7at1UcmKmPgFl8oy8G1YHgpwjE732b/7R5EB2LWn
  
X-Gm-Message-State: AKaTC01QFy2IxGmFXeqIFlaELd8n833ZihxbacROFw1zzAWo0Xkie6+tdonss85uj0pS1A==
X-Received: by 10.129.87.140 with SMTP id l134mr125546ywb.22.1479485957591;
        Fri, 18 Nov 2016 08:19:17 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.11.120 with SMTP id p53ls428178otd.13.gmail; Fri, 18 Nov
 2016 08:19:16 -0800 (PST)
X-Received: by 10.55.6.13 with SMTP id 13mr593379qkg.272.1479485956721;
        Fri, 18 Nov 2016 08:19:16 -0800 (PST)
Original-Received: from smtp123.iad3a.emailsrvr.com (smtp123.iad3a.emailsrvr.com. [173.203.187.123])
        by mx.google.com with ESMTPS id f67si5583892qkj.69.2016.11.18.08.19.15
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 18 Nov 2016 08:19:15 -0800 (PST)
Received-SPF: neutral (google.com: 173.203.187.123 is neither permitted nor denied by best guess record for domain of tom@honermann.net) client-ip=173.203.187.123;
Original-Received: from smtp16.relay.iad3a.emailsrvr.com (localhost [127.0.0.1])
	by smtp16.relay.iad3a.emailsrvr.com (SMTP Server) with ESMTP id 6D6665B16
	for <std-proposals@isocpp.org>; Fri, 18 Nov 2016 11:19:15 -0500 (EST)
X-Auth-ID: tom@honermann.net
Original-Received: by smtp16.relay.iad3a.emailsrvr.com (Authenticated sender: tom-AT-honermann.net) with ESMTPSA id 588075BA5
	for <std-proposals@isocpp.org>; Fri, 18 Nov 2016 11:19:15 -0500 (EST)
X-Sender-Id: tom@honermann.net
Original-Received: from [10.12.196.91] (pool-71-176-249-9.rcmdva.fios.verizon.net [71.176.249.9])
	(using TLSv1.2 with cipher DHE-RSA-AES128-SHA)
	by 0.0.0.0:587 (trex/5.7.12);
	Fri, 18 Nov 2016 11:19:15 -0500
In-Reply-To: <7366336.xLjCtBizz3@tjmaciei-mobl1>
X-Original-Sender: tom@honermann.net
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 173.203.187.123 is neither permitted nor denied by best guess
 record for domain of tom@honermann.net) smtp.mailfrom=tom@honermann.net
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:29467
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29467>

On 11/17/2016 5:58 PM, Thiago Macieira wrote:
> On quinta-feira, 17 de novembro de 2016 10:18:22 PST Tom Honermann wrote:
>> On 11/17/2016 03:13 AM, Jonathan M=C3=BCller wrote:
>>> Sorry if I'm asking the obvious question here: Why not guarantee that
>>> different string literals have different addresses and the same string
>>> literal has the same address and use const char* as non-type template
>>> parameters?
>> I believe one of the complications here is systems that support shared
>> libraries.  The opportunity to assign common addresses for equal string
>> literals doesn't arise until run-time.
> But everything that depended on those literals would also be resolved at
> runtime only (vague linkage).

Vague linkage is not supported by all compilers/linkers, at least not=20
when shared libraries are involved.

Consider the following example compiled with MSVC 2013:

$ cat t.h
extern inline const char* f() {
   return "text";
}

$ cat dll1.cpp
#include "t.h"
__declspec(dllexport) const char* dll1() {
   return f();
}

$ cat dll2.cpp
#include "t.h"
__declspec(dllexport) const char* dll2() {
   return f();
}

$ cat main.cpp
#include <cassert>
__declspec(dllimport) const char* dll1();
__declspec(dllimport) const char* dll2();
int main() {
   assert(dll1() =3D=3D dll2());
}

$ cl /LD dll1.cpp /Fedll1.dll
....

$ cl /LD dll2.cpp /Fedll2.dll
....

$ cl main.cpp /Femain.exe dll1.lib dll2.lib
....

$ ./main
Assertion failed: dll1() =3D=3D dll2(), file main.cpp, line 5

Since f() is an inline function, the returned string literal is required=20
to have the same address in all TUs:

C++14 [dcl.fct.spec] Function specifiers p4:
....
A string literal in the body of an extern inline function is the same=20
object in different translation units.
....

However, Microsoft's compiler/linker does not implement this requirement=20
across shared library boundaries.  Since shared libraries are not=20
described by the standard, it is arguable whether this is a=20
non-conformance issue or not.

If the above code is compiled into a single executable on Windows, the=20
assert does not fail.

Tom.

--=20
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 e=
mail 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/634b6222-d3e2-828b-75ec-f9da31b0493a%40honermann=
..net.

.
