view gcc/testsuite/g++.dg/template/pr86246.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line source

// { dg-do compile { target c++11 } }
// PR c++/86246 ICE in tsubst

namespace std {
  template<typename T> struct is_class {
    static constexpr bool value = true;
  };
  template<> struct is_class<double> {
    static constexpr bool value = false;
  };
}

class MyClass {
 public:
  operator double() const {
    return 1;
  }
  template<typename T>
  operator T() const {
    static_assert(std::is_class<T>::value, "problem");
    return T();
  }
};

template<typename T>
void SetValue(const MyClass& obj, T* value) {
  //  erroneously dispatched to operator T when T is double
  *value = obj.operator T();
}

int main() {
  MyClass obj;
  // works fine
  obj.operator double ();
  double x;
  // error, when operator T is called in SetValue
  SetValue(obj, &x);
}