<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Template type conversion operator not used leading to erroneous compilation error"
href="http://llvm.org/bugs/show_bug.cgi?id=21772">21772</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Template type conversion operator not used leading to erroneous compilation error
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.5
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mail@endlessvoid.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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};
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>