https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87748
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2018-10-25 00:00:00 |2019-4-16 Known to fail|9.0 | --- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- Another reproducer from PR 90080: struct false_type { static constexpr bool value = false; }; struct true_type { static constexpr bool value = true; }; template<bool, typename = void> struct enable_if { }; template<typename T> struct enable_if<true, T> { using type = T; }; template<typename T> T&& declval(); template<typename T, typename U, typename = U> struct is_static_castable : false_type {}; template<typename T, typename U> struct is_static_castable<T, U, decltype(static_cast<U>(declval<T>()))> : true_type {}; template<typename To, typename From, typename enable_if<is_static_castable<From*, To*>::value, int>::type = 0> To* safePtrCast(From* from) { return static_cast<To*>(from); } template<typename To, typename From, typename enable_if<!is_static_castable<From*, To*>::value, int>::type = 0> To* safePtrCast(From* from) { return dynamic_cast<To*>(from); } struct BarBase{ virtual ~BarBase() = default;}; struct Bar : virtual BarBase{}; Bar* foo(BarBase* b){ return safePtrCast<Bar>(b); } 90080.cc: In instantiation of ‘struct is_static_castable<BarBase*, Bar*, Bar*>’: 90080.cc:21:57: required by substitution of ‘template<class To, class From, typename enable_if<(! is_static_castable<From*, To*>::value), int>::type <anonymous> > To* safePtrCast(From*) [with To = Bar; From = BarBase; typename enable_if<(! is_static_castable<From*, To*>::value), int>::type <anonymous> = <missing>]’ 90080.cc:31:30: required from here 90080.cc:12:42: error: cannot convert from pointer to base class ‘BarBase’ to pointer to derived class ‘Bar’ because the base is virtual 12 | struct is_static_castable<T, U, decltype(static_cast<U>(declval<T>()))> : true_type | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 90080.cc:12:42: error: cannot convert from pointer to base class ‘BarBase’ to pointer to derived class ‘Bar’ because the base is virtual 90080.cc: In instantiation of ‘To* safePtrCast(From*) [with To = Bar; From = BarBase; typename enable_if<is_static_castable<From*, To*>::value, int>::type <anonymous> = 0]’: 90080.cc:31:30: required from here 90080.cc:18:12: error: cannot convert from pointer to base class ‘BarBase’ to pointer to derived class ‘Bar’ because the base is virtual 18 | return static_cast<To*>(from); | ^~~~~~~~~~~~~~~~~~~~~~