This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/86246] New: Template dispatching error inside a template function
- From: "tqchen at cs dot washington.edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Jun 2018 20:04:13 +0000
- Subject: [Bug c++/86246] New: Template dispatching error inside a template function
- Auto-submitted: auto-generated
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);
}