[LLVMbugs] [Bug 21772] New: Template type conversion operator not used leading to erroneous compilation error
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Dec 5 21:14:25 PST 2014
http://llvm.org/bugs/show_bug.cgi?id=21772
Bug ID: 21772
Summary: Template type conversion operator not used leading to
erroneous compilation error
Product: clang
Version: 3.5
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: mail at endlessvoid.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
The following code looks like valid C++ 11 but fails with error
"no matching constructor for initialization of 'Ptr<Shape>'"
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 <typename T>
struct Ptr {
Ptr(T* pp) : p{pp} { }
template <typename U>
explicit operator Ptr<U>(); // Convert Ptr<T> to Ptr<U>
private:
T* p;
};
template<typename T>
template<typename U>
Ptr<T>::operator Ptr<U>()
{
return Ptr<U>{p};
}
struct Shape {};
struct Circle : Shape {};
int main()
{
Circle c;
Ptr<Circle> pc{&c};
// The following instantiation causes the
// error. Ptr<Circle>::operator Ptr<Shape>() should be getting
// implicitly called on the argument pc, before the result is used
// to call Ptr<Shape>'s default copy constructor.
Ptr<Shape> ps{pc};
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141206/c0b6a6fb/attachment.html>
More information about the llvm-bugs
mailing list