Advertisement
fpelliccioni

Clang incorrect(?) compile time error

May 4th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. // clang++     -std=c++11 clang_error.cpp
  2.  
  3. #include <iostream>
  4. #include <type_traits>
  5.  
  6. template <typename ...Ts>
  7. struct other_variant
  8. {
  9.     union U
  10.     {
  11.     } u;
  12.  
  13.     void init() {} //workarround ... eliminate with metaprogramming
  14.     void get()  {} //workarround ... eliminate with metaprogramming
  15.  
  16. };
  17.  
  18. template <typename T, typename ...Ts>
  19. struct other_variant<T, Ts...> : other_variant<Ts...> //private other_variant<Ts...>
  20. {
  21.     typedef other_variant<Ts...> base;
  22.  
  23.  
  24.     union U
  25.     {
  26.         T e;
  27.         typename base::U bu;
  28.     } u;
  29.  
  30.  
  31.  
  32.     using base::init;
  33.  
  34.     void init( T const& value ) //constructor temporal replacement -- need inheriting constructors
  35.     {
  36.         u.e = value;
  37.     }
  38.  
  39.     using base::get;
  40.  
  41.     template <typename T2>
  42.     typename std::enable_if<std::is_same<T, T2>::value, T>::type
  43.     get()
  44.     {
  45.         return u.e;
  46.     }
  47.  
  48. };
  49.  
  50.  
  51. int main( /* int argc, char* argv[] */ )
  52. {
  53.     other_variant<int, double> ov;
  54.     ov.init(15.0);
  55.     std::cout << ov.get<double>() << std::endl;
  56.     std::cout << ov.get<int>() << std::endl;            //Compile-time error
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement