The following code compiles and links with Visual Studio
(both 2017 and 2019 with /permissive-
), but does not compile with either gcc
I believe this is a bug in MSVC. As for the std::default_delete::operator()
, the Standard says that [unique.ptr.dltr.dflt/4]:
Remarks: If T is an incomplete type, the program is ill-formed.
Since there is no "no diagnostic required" clause, a conforming C++ compiler is required to issue a diagnostic [intro.compliance/2.2]:
If a program contains a violation of any diagnosable rule or ..., a conforming implementation shall issue at least one diagnostic message.
together with [intro/compliance/1]:
The set of diagnosable rules consists of all syntactic and semantic rules in this document except for those rules containing an explicit notation that “no diagnostic is required” or which are described as resulting in “undefined behavior”.
GCC uses static_assert
to diagnose the type completeness. MSVC seemingly does not perform such a check. If it silently passes a parameter of std::default_delete::operator()
to delete
, then, this causes undefined behavior. Which might correspond with your observation. It may work, but until it is guaranteed by the documentation (as a non-standard C++ extension), I wouldn't use it.