Re: which compiler is right (either to compile or to barf)...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 2, 2022 at 6:18 PM leon zadorin <leonleon77@xxxxxxxxx> wrote:

> On Fri, Dec 2, 2022 at 5:37 PM LIU Hao <lh_mouse@xxxxxxx> wrote:
>
>> 在 2022/12/2 08:17, leon zadorin via Gcc-help 写道:
>> 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 { };   // 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> 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> s' is S
> considered incomplete type at that moment?
>
> ... 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 :)
>

sorry in the above 'static ::std::optional<S> s' should read 'static
::std::optional<S> opt' of course -- a bloody typo :)




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux