https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80475
Bug ID: 80475 Summary: Unevaluated combined delete new expression doesn't handle access error in class template SFINAE Product: gcc Version: 7.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: daniel.kruegler at googlemail dot com Target Milestone: --- The following code, compiled with gcc 7.0.1 20170419 (experimental) using the flags -Wall -Wextra -std=c++11 -pedantic or - alternatively - -Wall -Wextra -std=c++1z -pedantic //--- struct true_type { static const bool value = true; }; struct false_type { static const bool value = false; }; template<class T> T&& declval(); template<typename T, typename Arg, typename = void> struct is_direct_constructible_impl : false_type { }; template<typename T, typename Arg> struct is_direct_constructible_impl<T, Arg, decltype(::delete ::new T(declval<Arg>()))> : true_type { }; struct S { S(int); }; struct DCS { DCS(int) = delete; }; struct PCS { private: PCS(int); }; struct DDS { DDS(int); ~DDS() = delete; }; struct PDS { PDS(int); private: ~PDS() = default; }; int main() { static_assert(is_direct_constructible_impl<S, int>::value, "Ouch"); static_assert(!is_direct_constructible_impl<DCS, int>::value, "Ouch"); static_assert(!is_direct_constructible_impl<PCS, int>::value, "Ouch"); static_assert(!is_direct_constructible_impl<DDS, int>::value, "Ouch"); static_assert(!is_direct_constructible_impl<PDS, int>::value, "Ouch"); } //--- is rejected with the following diagnostics: <quote> prog.cc: In instantiation of 'struct is_direct_constructible_impl<PCS, int>': prog.cc:57:56: required from here prog.cc:20:25: error: 'PCS::PCS(int)' is private within this context decltype(::delete ::new T(declval<Arg>()))> ^~~~~~~~~~~~~~~~~~~~~~~ prog.cc:37:3: note: declared private here PCS(int); ^~~ prog.cc:20:25: error: 'PCS::PCS(int)' is private within this context decltype(::delete ::new T(declval<Arg>()))> ^~~~~~~~~~~~~~~~~~~~~~~ prog.cc:37:3: note: declared private here PCS(int); ^~~ prog.cc: In function 'int main()': prog.cc:57:3: error: static assertion failed: Ouch static_assert(!is_direct_constructible_impl<PCS, int>::value, "Ouch"); ^~~~~~~~~~~~~ prog.cc:57:18: error: 'PCS::PCS(int)' is private within this context static_assert(!is_direct_constructible_impl<PCS, int>::value, "Ouch"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ prog.cc:37:3: note: declared private here PCS(int); ^~~ prog.cc: In instantiation of 'struct is_direct_constructible_impl<PDS, int>': prog.cc:59:56: required from here prog.cc:22:1: error: 'PDS::~PDS()' is private within this context { }; ^ prog.cc:50:3: note: declared private here ~PDS() = default; ^ prog.cc:22:1: error: 'PDS::~PDS()' is private within this context { }; ^ prog.cc:50:3: note: declared private here ~PDS() = default; ^ prog.cc:59:3: error: static assertion failed: Ouch static_assert(!is_direct_constructible_impl<PDS, int>::value, "Ouch"); ^~~~~~~~~~~~~ prog.cc:59:18: error: 'PDS::~PDS()' is private within this context static_assert(!is_direct_constructible_impl<PDS, int>::value, "Ouch"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ prog.cc:50:3: note: declared private here ~PDS() = default; ^ </quote> This code example is somewhat different from PR 51222 because it uses "class template SFINAE" and is maybe related to PR 61806. This example occurred while discussing a possible alternative implementation of is_constructible, see PR 80390.