On Fri, Dec 2, 2022 at 5:37 PM LIU Hao wrote: > 在 2022/12/2 08:17, leon zadorin via Gcc-help 写道: > 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 :)