[cfe-dev] Template error without instantiation?

Ramneek Handa ramneekhanda at gmail.com
Wed Apr 24 08:02:28 PDT 2013


> > 
> > Hey folks,
> > Can you help check which compiler behaves correctly here? To my
> > untrained mind it seems to be a clang issue but seems too basic to have
> > been missed unintentionally?
> > 
> > Regards,
> > Ramneek
> > 
> > x- start -x
> > class A {};
> > 
> > class B {};
> > 
> > void myfun(A& myexp) {
> > }
> > 
> > template <typename T>
> > void mytest(const B &value)
> > {
> > myfun(A(value));
> > }
> > 
> > template <typename T>
> > void mytest(const T &value)
> > {
> > myfun(A(value));
> > }
> > x-end -x
> > 
> > 
> > *output from gcc:*
> > > gcc --version
> > 
> > gcc (GCC) 4.4.3
> > 
> > > gcc -c ~/test.cpp
> > Compiles!!
> > 
> > *output from clang:*
> > > clang++ --version
> > 
> > clang version 3.3 (2545b1d99942080bac4a74cda92c620123d0d6e9)
> > (2ff97832e593926ea8dbdd5fc5bcf367475638a9)
> > Target: x86_64-unknown-linux-gnu
> > Thread model: posix
> > 
> > clang++ ~/test.cpp
> > test.cpp:12:10: error: no matching conversion for functional-style cast
> > from 'const B' to 'A'
> > myfun(A(value));
> > ^~~~~~~
> > test.cpp:2:7: note: candidate constructor (the implicit copy
> > constructor) not viable: no known conversion from 'const B' to 'const A'
> > for 1st argument
> > class A {};
> > ^
> > test.cpp:2:7: note: candidate constructor (the implicit default
> > constructor) not viable: requires 0 arguments, but 1 was provided
> > test.cpp:18:4: error: no matching function for call to 'myfun'
> > myfun(A(value));
> > ^~~~~
> > test.cpp:6:6: note: candidate function not viable: expects an l-value
> > for 1st argument
> > void myfun(A& myexp) {
> > ^
> > 2 errors generated.
> 
> 






More information about the cfe-dev mailing list