public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: leon zadorin <leonleon77@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: which compiler is right (either to compile or to barf)...
Date: Thu, 1 Dec 2022 23:54:39 +0000	[thread overview]
Message-ID: <CAH6eHdT9q_GG-+paYTrLkP49wBHUaa3OGvkJKrtPUvrUXoOu9w@mail.gmail.com> (raw)
In-Reply-To: <CAPpySAY3fBsutWopQxCubbMZHbsWsc=nfm25C9_TwoMCCOXJJA@mail.gmail.com>

On Thu, 1 Dec 2022 at 23:27, leon zadorin via Gcc-help
<gcc-help@gcc.gnu.org> wrote:
>
> On Thu, Dec 1, 2022 at 8:35 PM LIU Hao <lh_mouse@126.com> wrote:
>
> >
> > I think this is a bug in Clang. Instantiation of `shared_ptr<T<U>>` is not
> > meant to instantiate
> > `T<U>`. Your code actually compiles fine if the definition of `J` was not
> > provided.
> >
> > --
> > Best regards,
> > LIU Hao
> >
>
> Thanks :) It is rather interesting, there is a discussion at
> https://github.com/llvm/llvm-project/issues/59292
> which may be pointing to implementation differences between stdlibc++ and
> libc++ etc.
>
> There is thinknig that it just may be UB in the originally-posted code (if
> so then clang is rather helpful there, but only when used with libstdc++
> apparently.. as I haven't personally verified the delta between building
> against different libs :) :) )
>
> The current thought prorcess is that std component must be allowed by the
> standard to be instantiated with incomplete type T. And vector is allowed
> so indeed (but I think it must be complete by the time its members, e.g.
> via member-function invocation, are referenced)... so then it may come down
> to std::optional and its implementation -- whether its ctor is referencing
> any vector's members (dtor etc.) ...
>
> I suppose the official way would be to find whether ::std::optional may be
> instantiated with incomplete type T

It may not be.


 (say even if only when using default,
> no value present, ctor overload)... and if it not mentioned of being able
> to do so then it would be a bug in the original code (at which point having
> some toolchain being able to detect it is rather super nice :) :)
>
> I dont know to be honest if standard's doco for such ctor , e.g.
>    constexpr optional() noexcept; constexpr optional(nullopt_t) noexcept;
>          Postconditions: *this does not contain a value.
> <https://timsong-cpp.github.io/cppwp/n4861/optional#ctor-1.sentence-1>
>          Remarks: No contained value is initialized.
> <https://timsong-cpp.github.io/cppwp/n4861/optional#ctor-2.sentence-1>
>          For every object type T these constructors are constexpr
> constructors
>
> would be sufficient to infer the ability to instantiate with incomplete
> type... probably not (I'm not enough of an expert to see through this with
> my cloudy head atm :)

Those constructors are irrelevant. It's undefined to instantiate *any*
std::lib template with an incomplete type unless *explicitly*
permitted. It is explicitly permitted for vector and shared_ptr. It is
not permitted for optional.

  reply	other threads:[~2022-12-01 23:54 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 [this message]
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
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=CAH6eHdT9q_GG-+paYTrLkP49wBHUaa3OGvkJKrtPUvrUXoOu9w@mail.gmail.com \
    --to=jwakely.gcc@gmail.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).