[Bug c++/86246] New: Template dispatching error inside a template function
tqchen at cs dot washington.edu
gcc-bugzilla@gcc.gnu.org
Wed Jun 20 20:04:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86246
Bug ID: 86246
Summary: Template dispatching error inside a template function
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tqchen at cs dot washington.edu
Target Milestone: ---
See bellow minimum reproducible example. There is also evidence that it still
exists in gcc-8.1, gcc-7 or prior versions do not have this problem
#include <type_traits>
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) {
// always dispatches to operator T even if 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);
}
More information about the Gcc-bugs
mailing list