[cfe-dev] Template error without instantiation?

Douglas Gregor dgregor at apple.com
Wed Apr 24 09:53:47 PDT 2013


On Apr 24, 2013, at 9:22 AM, Ramneek Handa <ramneekhanda at gmail.com> wrote:

> 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?

Both behaviors are "correct", in the sense that a compiler is allowed to diagnose templates that have no valid instantiations (but is not required to). Clang tends to be more picky about such things. See

	http://clang.llvm.org/compatibility.html#bad_templates

	- Doug

> 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 --versiongcc (GCC) 4.4.3
> 
>> gcc -c ~/test.cppCompiles!!
> 
> *output from clang:*
>> clang++ --versionclang 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.
> -RH
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130424/995f02a4/attachment.html>


More information about the cfe-dev mailing list