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

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

 



在 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<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.


--
Best regards,
LIU Hao

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[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