[Bug c++/58449] New: templated cast operator and failed template deduction on copy-construction via assign operator
forestshade at hotmail dot de
gcc-bugzilla@gcc.gnu.org
Tue Sep 17 18:39:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58449
Bug ID: 58449
Summary: templated cast operator and failed template deduction
on copy-construction via assign operator
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: forestshade at hotmail dot de
The following code produces a compiler error:
-------------------------
#include <iostream>
using namespace std;
struct S {
};
class A {
public:
A(void* ptr) : ptr(ptr) {}
void* ptr;
template<typename T>
operator const T&() const {
return *static_cast<T*>(ptr);
}
};
int main() {
S test;
A a(&test);
S s = a;
return 0;
}
-------------------------
while this one doesn't:
-------------------------
#include <iostream>
using namespace std;
struct S {
};
class A {
public:
A(void* ptr) : ptr(ptr) {}
void* ptr;
operator const S&() const {
return *static_cast<S*>(ptr);
}
};
int main() {
S test;
A a(&test);
S s = a;
return 0;
}
-------------------------
I'm not exactly sure if the standard allows the line "S s = a;" in this case
but the code above should either both succeed or both fail.
More information about the Gcc-bugs
mailing list