在 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`. 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. -- Best regards, LIU Hao