From: LIU Hao <lh_mouse@126.com>
To: leon zadorin <leonleon77@gmail.com>, gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: which compiler is right (either to compile or to barf)...
Date: Fri, 2 Dec 2022 14:37:12 +0800 [thread overview]
Message-ID: <81026ee4-8f45-3d45-57ca-a9abed92c722@126.com> (raw)
In-Reply-To: <CAPpySAbNvfseoJSHoym9ZAKZ=UkBmBDy8k77_WrJFwef2LKC5w@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 1055 bytes --]
在 2022/12/2 08:17, leon zadorin via Gcc-help 写道:
> Thanks Jonathan for clarifying, as always - very precise and helpful. I'll
> close the issue on the clang side also.
No, you do not _instantiate_ `J<X>`. The behavior would have been undefined if you did.
`::std::shared_ptr<J<X>> p;` is fine on itself, because `J<X>` is not instantiated. On the other
hand, `::std::shared_ptr<J<X>> p(static_cast<J<X>*>(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<struct foo> ptr(
(struct foo*) nullptr); // instantiates `delete (struct foo*) ___`
struct foo { };\x0f // the line above would have undefined behavior without this
So, either way, your code is not undefined.
--
Best regards,
LIU Hao
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
next prev parent reply other threads:[~2022-12-02 6:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 4:51 leon zadorin
2022-12-01 9:35 ` LIU Hao
2022-12-01 23:26 ` leon zadorin
2022-12-01 23:54 ` Jonathan Wakely
2022-12-01 23:56 ` Jonathan Wakely
2022-12-02 0:17 ` leon zadorin
2022-12-02 6:37 ` LIU Hao [this message]
2022-12-02 7:18 ` leon zadorin
2022-12-02 7:22 ` leon zadorin
2022-12-02 7:45 ` LIU Hao
2022-12-02 8:34 ` leon zadorin
2022-12-02 9:16 ` leon zadorin
2022-12-02 10:50 ` leon zadorin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81026ee4-8f45-3d45-57ca-a9abed92c722@126.com \
--to=lh_mouse@126.com \
--cc=gcc-help@gcc.gnu.org \
--cc=leonleon77@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).