From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id DC89A3855149 for ; Fri, 2 Dec 2022 07:19:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DC89A3855149 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1029.google.com with SMTP id o5-20020a17090a678500b00218cd5a21c9so4355765pjj.4 for ; Thu, 01 Dec 2022 23:19:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=N0XFRSyZL7mpKbp2Oi8RrXxOsv7376pxLb24LfPA2n4=; b=B5NFxrN49Tl4JcGn5hWNRYyR5256/8Pb1gXZxAX6HFHN0D15A0wA7H4EM5wgenkAHp DEqeJjcQwTygckYorOwIEhMGSgwRPNS74nzrFi7yipM6XjiFvpU9PBXQqQXq+O0B0N6K l3DU0U2qDKTRh/cXmd6RaG4i2VR1bMFw6P/j9B2nLghMdKIhZnIhrwKVRP8NNFZXbvE2 cN7uLRV6OjBsoCYeKHbwKfTGR2YDxEO6QCQyxPYbQMAkJizy0uRecFbWn196V9sCUwPw dwaA8xMuarQgJZwdUZBUpb6xV9rHdcVPqonNDPV1p7CsM1lni+4MboFvQJYfaLcPU8lK 5jKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=N0XFRSyZL7mpKbp2Oi8RrXxOsv7376pxLb24LfPA2n4=; b=q3q0cqQOdt0UFQoEBTlu5p2lC+iFqetXEkqdv7fZ2iOh7hmyynpnt06K3rXRBVY7Na Z6cOBhXc+PcJPAks/YNFq2k/ebgtGb+St3SzJXgjIvBddcFylbYA729H+wNrckxG0xWj wxvXKc/z8wR0kYsoasS81S4Wjeown9wh+GKNRB7s99MeRZcqU50/Vdx6aqJ8dumX08j0 OKzRyQhfBkO8zcOQNQl5zuAS2vw2x4MCmmVnDXi4nix8aZie7/sZdfG3GGSmvazxlGib 8dU6dBgNV9tNLpnu8Q9/0jfTDxmc6PnhMdzhLvfVM2CE3IOMCgvp43zwLgEZq1uvc7+q 05ag== X-Gm-Message-State: ANoB5pkyA+GJyQZa2l8HFpUVdf1EqNVF3SJ51xshJPBvVy0W0M9FF6xk mh36xFIgJpcXo3ssd3Q63zm/c4ORgLiKFTC7IG0lj56N X-Google-Smtp-Source: AA0mqf7TiwYry3kIu06sMTNbVtYc9XywzhV9SO1ufiql3F/BXy/b40fKoiGLa7nmNF3LgTdI19K0l+upwaxzfMINR2Q= X-Received: by 2002:a17:902:7087:b0:189:4de4:e71b with SMTP id z7-20020a170902708700b001894de4e71bmr44399128plk.159.1669965540741; Thu, 01 Dec 2022 23:19:00 -0800 (PST) MIME-Version: 1.0 References: <81026ee4-8f45-3d45-57ca-a9abed92c722@126.com> In-Reply-To: <81026ee4-8f45-3d45-57ca-a9abed92c722@126.com> From: leon zadorin Date: Fri, 2 Dec 2022 18:18:48 +1100 Message-ID: Subject: Re: which compiler is right (either to compile or to barf)... To: gcc-help Content-Type: multipart/alternative; boundary="000000000000d7d91a05eed32646" X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000d7d91a05eed32646 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Dec 2, 2022 at 5:37 PM LIU Hao wrote: > =E5=9C=A8 2022/12/2 08:17, leon zadorin via Gcc-help =E5=86=99=E9=81=93: > No, you do not _instantiate_ `J`. The behavior would have been > undefined if you did. > `::std::shared_ptr> p;` is fine on itself, because `J` is not > instantiated. On the other > hand, `::std::shared_ptr> p(static_cast*>(nullptr));` is > undefined, as it instantiates a > delete expression. > > > In addition to that, [temp.point]/1 specifies that the point of > instantiation of members of a class > template _follows the end of_ namespace scope of the most enclosing > specialization. This allows use > before definition, which is not permitted for non-template classes: > > std::shared_ptr ptr( > (struct foo*) nullptr); // instantiates `delete (struct foo*) > ___` > > struct foo { }; // the line above would have undefined behavior > without this > > > So, either way, your code is not undefined. > > Wow, ok, many thanks -- veeery interesting :) So I'm getting confused a little :) Let me summarize here: (1) On the one hand, given that I do instantiate ::std::optional with S (whith has member v whose elements' types, I guess(?) are at the line of declaring 'static ::std::optional s', are still incompletely denifed, i.e. X) -- the clang discussion appears to say that at this moment optional is instantiated and S is incomplete (?) ... as so it is a UB... which I understood Jonathan's comment to relate to as well. (2) However, from your comment it would appear that 'instantiation of members of class template' is done afterwards anyways... I suppose to reconcile both bits of info: (a) 'instantitation of members of class template' ... is it the same for instantitaion of the class template itself? (because UB specs appears to provide restrictions on std lib class instantiations, not specifically to inner members, but just for whole class)?; and (b) in the above code right at the line 'static ::std::optional s' is S considered incomplete type at that moment? ... I'm just trying to figure out whether template "::std::optional" is, itself, being instantiated at that very line (never mind its members) and if type S at that moment is considered to be incomplete... in which case it is UB... if not then may be its not a UB... I am confused :) ha ha :) wouldn't be the first time though :) --000000000000d7d91a05eed32646--