fork download
  1. #include <type_traits>
  2.  
  3. struct T2;
  4. struct T1 {
  5. T1(){}
  6. T1(int){}
  7. operator T2();
  8. };
  9. struct T2 {
  10. operator int() { return 0; }
  11. };
  12. struct T3 {
  13. operator int() { return 0; }
  14. };
  15. T1::operator T2() { return T2(); }
  16.  
  17. using namespace std;
  18. using X = T1;
  19. using Y = T2;
  20. using Z = T3;
  21. int main()
  22. {
  23.  
  24. true?T2():T3(); // int
  25. static_assert(std::is_same<std::common_type_t<T2,
  26. T3>,
  27. int>::value,
  28. "Not int");
  29.  
  30. true?T1():(true?T2():T3()); // T1
  31. static_assert(std::is_same<std::common_type_t<T1,
  32. std::common_type_t<T2,
  33. T3>>,
  34. T1>::value,
  35. "Not T1");
  36.  
  37. // -----------------------------------------
  38.  
  39. true?T1():T2(); // T2
  40. static_assert(std::is_same<std::common_type_t<T1,
  41. T2>,
  42. T2>::value,
  43. "Not T2");
  44.  
  45. true?(true?T1():T2()):T3(); // int
  46. static_assert(std::is_same<std::common_type_t<std::common_type_t<T1,
  47. T2>,
  48. T3>,
  49. int>::value,
  50. "Not int");
  51.  
  52. // -----------------------------------------
  53.  
  54. static_assert( is_same<common_type_t< X, common_type_t<Y,Z> >,
  55. common_type_t< common_type_t<X,Y>, Z > >::value,
  56. "Don't match");
  57. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:54:5: error: static assertion failed: Don't match
     static_assert( is_same<common_type_t< X, common_type_t<Y,Z>    >,
     ^
stdout
Standard output is empty