llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.09k stars 12k forks source link

Template type conversion operator not used leading to erroneous compilation error #22146

Open llvmbot opened 9 years ago

llvmbot commented 9 years ago
Bugzilla Link 21772
Version 3.5
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@tavianator

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} { }

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}; }

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 2 years ago

mentioned in issue llvm/llvm-bugzilla-archive#21991

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 9 years ago

Bug llvm/llvm-bugzilla-archive#21991 has been marked as a duplicate of this bug.