Open llvmbot opened 9 years ago
The following code looks like valid C++ 11 but fails with error
"no matching constructor for initialization of 'Ptr'"
It compiles ok on gcc 4.9. Based on example code taken from Stroustrup's The C++ Programming Language 4th edition, pp 764-765.
template struct Ptr { Ptr(T* pp) : p{pp} { }
template <typename U> explicit operator Ptr<U>(); // Convert Ptr<T> to Ptr<U>
private: T* p; };
template template Ptr::operator Ptr() { return Ptr{p}; }
struct Shape {}; struct Circle : Shape {};
int main() { Circle c; Ptr pc{&c}; // The following instantiation causes the // error. Ptr::operator Ptr() should be getting // implicitly called on the argument pc, before the result is used // to call Ptr's default copy constructor. Ptr ps{pc}; }
mentioned in issue llvm/llvm-bugzilla-archive#21991
Bug llvm/llvm-bugzilla-archive#21991 has been marked as a duplicate of this bug.
Extended Description
The following code looks like valid C++ 11 but fails with error
"no matching constructor for initialization of 'Ptr'"
It compiles ok on gcc 4.9. Based on example code taken from Stroustrup's The C++ Programming Language 4th edition, pp 764-765.
template
struct Ptr {
Ptr(T* pp) : p{pp} { }
private: T* p; };
template
template
Ptr::operator Ptr()
{
return Ptr{p};
}
struct Shape {}; struct Circle : Shape {};
int main() { Circle c; Ptr pc{&c};
// The following instantiation causes the
// error. Ptr::operator Ptr() should be getting
// implicitly called on the argument pc, before the result is used
// to call Ptr's default copy constructor.
Ptr ps{pc};
}