c++ - GCC 4.9 ambiguous overload template specialization -


i'm running issue gcc 4.9.2 (with -std=c++11) not compiling piece of code error message being

call of overloaded 'insertdataintoinputmap(int&, boost::shared_ptr&)' ambiguous

the code compile msvc 2013

#include <iostream> #include <map> #include <boost/shared_ptr.hpp>  struct proxy {     typedef std::map<int, int> inputdatamap;         int a; };  template<class c, class d> void insertdataintoinputmap(     const typename c::inputdatamap::key_type& key,     const d val) {     std::cout << "not shared\n"; }  template<class c, class d> void insertdataintoinputmap(     const typename c::inputdatamap::key_type& key,     const boost::shared_ptr<d> val) {     if (val)     {         std::cout << "shared\n";     } }  int main() {     int a;     boost::shared_ptr<double> x(new double(4.5));      insertdataintoinputmap<proxy>(a, x); } 

while following compile both gcc , msvc:

#include <iostream> #include <boost/shared_ptr.hpp>  template<class c, class d> void insertdataintoinputmap(     const c& key,     const d val) {     std::cout << "not shared\n"; }  template<class c, class d> void insertdataintoinputmap(     const c& key,     const boost::shared_ptr<d> val) {     if (val)     {         std::cout << "shared\n";     } }  int main() {     int = 0;     boost::shared_ptr<double> x(new double(4.5));      insertdataintoinputmap<int>(a, x);      return 0; } 

i have thought compiler should take function boost::shared_ptr argument in both cases?

this problem can reduced imprecision in partial ordering: pairs in no template-parameters appear involved in deduction still considered , compaired. issue addressed cwg #455 , #885 well.

in example, overload resolution isn't able distinguish overloads. hence partial ordering necessary. , partial ordering try perform deduction twice, parameter type p being typename c::inputdatamap::key_type.
however, deduction doomed fail, since c solely appears in non-deduced context. i.e. type both templates (for particular pair) not @ least specialized type respective other template - , that, in turn, implies neither of templates more specialized other.

as noted @t.c., resolution of cwg #1391 helps. part in particular:

change 14.8.2.4 [temp.deduct.partial] paragraph 4 follows:

each type nominated above parameter template , corresponding type argument template used types of p , a. if particular p contains no template-parameters participate in template argument deduction, p not used determine ordering.

now, first parameter pair entirely ignored in both ways (as types of c solely determined explicit argument list), , second overload found more specialized.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -