0

In VS2015 (but not using various other compilers on multiple platforms, including VS10), I'm getting

Charlie\Gamma.cpp(224): error C2668: 'boost::make_shared': ambiguous call to overloaded function
  E:\C++Libs\boost_1_60_0\boost/smart_ptr/make_shared_object.hpp(246): note: could be 'boost::shared_ptr<T> boost::make_shared<Able::Bravo::Charlie::Dog,Able::Bravo::Charlie::Egg&,const uint32_t&,const Frank&>(Able::Bravo::Charlie::Egg &,const uint32_t &,const Frank &)' [found using argument-dependent lookup]
          with
          [
              T=Able::Bravo::Charlie::Dog
          ] (compiling source file Charlie\Gamma.cpp)
  D:\@Prog-Charon\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\memory(968): note: or       'std::shared_ptr<Able::Bravo::Charlie::Dog> std::make_shared<Able::Bravo::Charlie::Dog,Able::Bravo::Charlie::Egg&,const uint32_t&,const Frank&>(Able::Bravo::Charlie::Egg &,const uint32_t &,const Frank &)' (compiling source file Charlie\Gamma.cpp)
  Charlie\Gamma.cpp(224): note: while trying to match the argument list '(Able::Bravo::Charlie::Egg, const uint32_t, const Frank)'

(with my closed-source names sanitized, and Boost and standard names left intact)

The code is:

namespace Able {
namespace Bravo {
namespace Charlie {


using std::string;
using std::tr1::shared_ptr;
using std::tr1::make_shared;

⋮  // then later in the file

shared_ptr<Dog> Gamma::knockout (const Hotel& target)
{
   Egg softboiled (target.ID);
   softboiled.sequence ^= 0x40000000;
   return make_shared<Dog>(softboiled, target.kin, Frank::myself());
}

The use of make_shared sees std::tr1::make_shared brought into scope via the using declaration, and that's what is intended. The error shows that it is resolving to std::make_shared, and I expect that tr1 is just a bunch of typedefs for backward compatibility.

But it also reports finding boost::make_shared via argument-dependent lookup. But the arguments are

Able::Bravo::Charlie::Egg &,
const uint32_t &,
const Frank &

none of which are in the boost namespace.

So why would it be finding boost::make_shared via argument-dependent lookup?

Hmm, could it be because Frank is derived privately from boost::totally_ordered1 (and Egg from boost::totally_ordered)? Is this a change in the lookup rules, a fix or bug in one of the compilers, or something like that?

If that's correct, then any use of boost's mix-in types will cause all sorts of ambiguities as old boost stuff matches the names of now-standard functions, or common names in general. These private base classes end up polluting my class's namespace without even being apparent in the public interface that it's at all related to boost! That can't be right.


Update: This occurs with Boost 1.60 but not with Boost 1.59. So disregard my conclusion that it varies by compiler/platform: it's worked on various platforms with an older version of Boost.

I moved to the latest release Boost as a first step to solve compile-time issues happening with Boost, and it seems to have introduced another instead.

Boost’s operators.hpp defines template struct totally_ordered2 etc. within namespace boost, not anything more fancy, in Boost version 1.59.

3
  • Is this code also doesn't compile? melpon.org/wandbox/permlink/M4aMcmtJcHDxOJ70
    – ForEveR
    Dec 24, 2015 at 8:35
  • 1
    Access control doesn't affect name lookup. Probably some other boost header you use pulled in boost::make_shared in 1.60 but not 1.59.
    – T.C.
    Dec 24, 2015 at 15:48
  • Please provide a minimal, complete, and verifiable example.
    – Barry
    Dec 24, 2015 at 17:37

1 Answer 1

4

It does look like it's because, like you say, Frank derives from boost::totally_ordered1.

§ 3.4.2 [basic.lookup.argdep] of the C++14 standard (n4296) specifies the sets of namespaces and classes that are considered. Here is § 3.4.2/2:

For each argument type T in the function call, there is a set of zero or more associated namespaces and a set of zero or more associated classes to be considered. The sets of namespaces and classes is determined entirely by the types of the function arguments (and the namespace of any template template argument). Typedef names and using-declarations used to specify the types do not contribute to this set. The sets of namespaces and classes are determined in the following way:

and § 3.4.2/2.2 concerns class types:

If T is a class type (including unions), its associated classes are: the class itself; the class of which it is a member, if any; and its direct and indirect base classes. Its associated namespaces are the innermost enclosing namespaces of its associated classes. Furthermore, if T is a class template specialization, its associated namespaces and classes also include: the namespaces and classes associated with the types of the template arguments provided for template type parameters (excluding template template parameters); the namespaces of which any template template arguments are members; and the classes of which any member templates used as template template arguments are members. [ Note: Non-type template arguments do not contribute to the set of associated namespaces. —end note ]


Edit: Just saw your update, not sure what could account for it working in 1.59 but not 1.60 under the same compiler, flags, and C++ version.

3
  • That's what I was wondering before the Update. If that's (private base) a clarification or change in C++14 I think it would cause a lot of breakage, for these boost mix-ins in particular. The library would need to provide those mix-ins in different namespace or behind a typedef.
    – JDługosz
    Dec 24, 2015 at 9:23
  • 2
    If I follow, if boost::totally_ordered were really boost::internal::to then the boost::internal would be searched, not boost itself; and the fact that I used a typedef boost::totally_ordered to alias it would not cause boost to be nominated: it follows the typedef to the real class and nominates that. Right?
    – JDługosz
    Dec 24, 2015 at 9:25
  • I think that's correct. That's probably what this means: "Typedef names and using-declarations used to specify the types do not contribute to this set." Dec 24, 2015 at 19:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.