fork download
  1. #include <type_traits>
  2.  
  3. template <class To, class From>
  4. To test() {
  5. return std::declval< From >();
  6. }
  7.  
  8. struct Base {};
  9.  
  10. struct Derived : public Base {};
  11.  
  12. int main()
  13. {
  14. test<Derived*, Base*>();
  15. }
  16.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘To test() [with To = Derived*; From = Base*]’:
prog.cpp:14:26:   required from here
prog.cpp:5:33: error: invalid conversion from ‘Base*’ to ‘Derived*’ [-fpermissive]
     return std::declval< From >();
                                 ^
In file included from prog.cpp:1:0:
/usr/include/c++/6/type_traits: In instantiation of ‘typename std::add_rvalue_reference< <template-parameter-1-1> >::type std::declval() [with _Tp = Base*; typename std::add_rvalue_reference< <template-parameter-1-1> >::type = Base*&&]’:
prog.cpp:5:32:   required from ‘To test() [with To = Derived*; From = Base*]’
prog.cpp:14:26:   required from here
/usr/include/c++/6/type_traits:2270:7: error: static assertion failed: declval() must not be used!
       static_assert(__declval_protector<_Tp>::__stop,
       ^~~~~~~~~~~~~
stdout
Standard output is empty