Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7639493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:25:54+00:00 2026-05-31T08:25:54+00:00

Using Visual Studio 2010 SP1: #include <vector> //namespace XXX { struct Test { bool

  • 0

Using Visual Studio 2010 SP1:

#include <vector>

//namespace XXX {
  struct Test
  {
    bool operator==(const Test& r) const  { return true; }
  };
//}
//typedef XXX::Test Test;

template <typename T> inline bool operator!=(const T& l,const T& r) 
{ return !(l==r); }

int main()
{
  std::vector<Test> vt;
  std::vector<Test> vt2 = std::move(vt);
  return 0;
}

If I compile the code above as is, it fails with this error:

1>C:\apps\MVS10\VC\include\vector(609): error C2593: 'operator !=' is ambiguous
1>          C:\apps\MVS10\VC\include\xmemory(268): could be 'bool std::operator !=<_Ty,_Ty>(const std::allocator<_Ty> &,const std::allocator<_Ty> &) throw()'
1>          with
1>          [
1>              _Ty=Test
1>          ]
1>          test.cpp(11): or       'bool operator !=<std::allocator<_Ty>>(const T &,const T &)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Ty=Test,
1>              T=std::allocator<Test>
1>          ]
1>          while trying to match the argument list '(std::allocator<_Ty>, std::allocator<_Ty>)'
1>          with
1>          [
1>              _Ty=Test
1>          ]
1>          C:\apps\MVS10\VC\include\vector(606) : while compiling class template member function 'void std::vector<_Ty>::_Assign_rv(std::vector<_Ty> &&)'
1>          with
1>          [
1>              _Ty=Test
1>          ]

… where vector(609) resolves to this line:

        else if (get_allocator() != _Right.get_allocator())

OTOH, if I uncomment the namespace XXX-related lines, it compiles without complaint.

I have to think this is a compiler bug but I’m looking for some independent verification.

EDIT: Just by way of explanation, I came across this situation when recompiling some old code with VS2010 for the first time. The global operator was some cruft from years past (now removed). I just couldn’t understand why some code failed and others didn’t. The code above is my distillation of the failed case (obviously, old code would not contain calls to std::move()).

UPDATE: I logged a bug with MS and they responded that this has been fixed “in the next release of the compiler” – which I presume means Visual C++ 11. See: http://connect.microsoft.com/VisualStudio/feedback/details/731692/regression-involving-global-operator-and-std-vector

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:25:56+00:00Added an answer on May 31, 2026 at 8:25 am

    It’s a bug.

    You’ve decided to provide operator!= for all types ever which is obviously going to cause conflicts with types which already have such an operator defined.

    Argument Dependent Lookup during the resolution of a call to operator!= between two std::allocator<Test>s inside your library implementation [1] allows the namespace of Test to be searched (as well as std) when trying to find the operator!= to use [2].

    So:

    • in your broken case, that namespace is the global namespace, which also contains a operator!= that matches. Now, this shouldn’t matter, because the function in namespace std is a better match [3]; the VS bug is that an ambiguity is raised instead.

    • but when Test is instead in namespace XXX (despite the typedef), the namespace searched due to the above rule is instead the namespace XXX, which contains no conflicting definition for operator!=.

    Best not define operators for all types ever like that, in any case.


    [1] Some part of the implementation for your line std::vector<Test> vt2 = std::move(vt); on your compiler/library impl is invoking bool operator!=<std::allocator<Test>>(const std::allocator<Test>&, const std::allocator<Test>&).

    [2] Citations follow:

    [C++11: 3.4.2/1]: When the postfix-expression in a function call (5.2.2) is an unqualified-id, other namespaces not considered during the usual unqualified lookup (3.4.1) may be searched, and in those namespaces, namespace-scope friend function declarations (11.3) not otherwise visible may be found. These modifications to the search
    depend on the types of the arguments
    (and for template template arguments, the namespace of the template argument).

    [C++11: 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:

    • [..]
    • 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 namespaces of which its associated classes are members. 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 ]
    • [..]

    [3] Citations follow:

    [C++11: 13.3.3/1]: Given these definitions, a viable function F1 is defined to be a better function than another viable function F2 if for all arguments i, ICSi(F1) is not a worse conversion sequence than ICSi(F2), and then:

    • [..]
    • F1 and F2 are function template specializations, and the function template for F1 is more specialized than the template for F2 according to the partial ordering rules described in 14.5.6.2.

    [C++11: 14.5.6.2/2]: Partial ordering selects which of two function templates is more specialized than the other by transforming each template in turn (see next paragraph) and performing template argument deduction using the function type. The deduction process determines whether one of the templates is more specialized than the other. If so, the more specialized template is the one chosen by the partial ordering process.

    My interpretation is that this process determines that the function in std is “more specialised” than the one in the global namespace, so there in fact should not be an ambiguity.


    Thanks @BoPersson and @DavidRodríguez for your valuable contributions to this kick-ass answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Visual Studio 2010 Ultimate Beta 2. What is the relevant namespace/classes
I am using Visual Studio 2010 SP1 in Windows 7 64bit dev box. My
I am using Visual Studio 2010 Ultimate SP1 and have set my project's target
Using Visual Studio 2010 SP1, SQL server 2008: Motherboard recently failed and I migrated
I am trying to create a VSPackage project (using the Visual Studio 2010 SP1
Setup: I am using MVC 3, EF 4.1, Visual Studio 2010 SP1 with Power
I have been using Visual Studio 2010 SP1 for C++ in the default setting
I am using Visual Studio 2010 SP1 with MVC3 Tools Update, and EF 4.1
Working with Visual Studio 2010 SP1 (beta?) I'm using Razor cshtml files however I
I already have Visual Studio 2010 SP1 installed. I am using express edition. Also,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.