fork download
  1. template <typename T> struct item {
  2. operator item<const T> () const { return item<const T>(); }
  3. };
  4.  
  5. void conversionToConstRefWorks (const item<const int> &) { }
  6.  
  7. template <typename T>
  8. void butNotWhenTemplated (const item<const T> &) { }
  9.  
  10. int main () {
  11.  
  12. item<int> i;
  13. item<const int> ci;
  14.  
  15. // these all compile fine:
  16. conversionToConstRefWorks(ci);
  17. conversionToConstRefWorks(i);
  18. butNotWhenTemplated(ci);
  19.  
  20. // but this one fails:
  21. butNotWhenTemplated(i);
  22.  
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:21:24: error: no matching function for call to ‘butNotWhenTemplated(item<int>&)’
   butNotWhenTemplated(i);
                        ^
prog.cpp:8:6: note: candidate: ‘template<class T> void butNotWhenTemplated(const item<const T>&)’
 void butNotWhenTemplated (const item<const T> &) { }
      ^~~~~~~~~~~~~~~~~~~
prog.cpp:8:6: note:   template argument deduction/substitution failed:
prog.cpp:21:24: note:   types ‘const T’ and ‘int’ have incompatible cv-qualifiers
   butNotWhenTemplated(i);
                        ^
stdout
Standard output is empty