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 15:45:43 +0800 [thread overview]
Message-ID: <69b994c3-b1e2-6752-4bc0-5d706bfc0da3@126.com> (raw)
In-Reply-To: <CAPpySAaHZ6gwfQDGS22SG1+dzJjkqjtZbTvv7vm+zq=FSwOnGw@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2746 bytes --]
在 2022/12/2 15:18, leon zadorin via Gcc-help 写道:
> (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> 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.
>
Yes this requires `S` to be complete.
> (2) However, from your comment it would appear that 'instantiation of
> members of class template' is done afterwards anyways...
>
Only `S` itself is required to be complete.
In your code:
struct S {
::std::vector<::std::shared_ptr<J<X>>> v;
};
`S` _is_ complete. It does not matter whether it contains a `vector` of or a `shared_ptr` to
incomplete types, because the standard allows so. ([vector.overview] 4, [util.smartptr.shared] 2)
> 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
>
No.
```
struct T;
extern T* eptr; // okay; pointer to incomplete type
struct S
{
shared_ptr<T> mptr; // okay; `shared_ptr` to incomplete type
};
void
use_s()
{
S s; // oayk; `S` is complete
s.mptr.reset(); // okay; `reset()` does not require `T` to
// be complete
s.mptr.reset(::eptr); // error; instantiates the default
// deleter expression which requires
// `T` to be complete
}
```
> (b) in the above code right at the line 'static ::std::optional<S> s' is S
> considered incomplete type at that moment?
>
No. See above.
> ... I'm just trying to figure out whether template "::std::optional<S>" 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 :)
If `shared_ptr` is a bad example for you, here is a much simpler one:
```
struct incomplete;
struct complete
{
incomplete* ptr; // okay
incomplete& ref; // also okay
incomplete val; // invalid use of incomplete type
};
```
--
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 7:45 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
2022-12-02 7:18 ` leon zadorin
2022-12-02 7:22 ` leon zadorin
2022-12-02 7:45 ` LIU Hao [this message]
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=69b994c3-b1e2-6752-4bc0-5d706bfc0da3@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).