C2593: 'operator <<' is ambiguous

G

Guest

Does anybody else see this in VS.NET 2003?

When I get a genuine C++ compiler error (could be anything, usually
innocuous) it's regularly followed by a slew of these spurious and completely
unrelated ones:

error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\ostream(697): could be 'std::basic_ostream<_Elem,_Traits>
&std::blush:perator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits>
&,const char *)' [found using argument-dependent lookup]
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\ostream(697): or 'std::basic_ostream<_Elem,_Traits>
&std::blush:perator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits>
&,const char *)' [found using argument-dependent lookup]
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
while trying to match the argument list '(std::blush:stream, const char
[4])'

There's probably one of these for every use of operator<< in the file, but
I've never bothered to check that; there are just lots. Note that where it
says "could be X or Y", X and Y are identical! There's nothing obviously
wrong with the use of these operators, and if I fix the real error the
spurious ones disappear.

If nobody else is getting this, what might I be doing to make it happen?
It's beginning to really irritate me.

Rob
 
T

Tom Widmer [VC++ MVP]

rjd said:
Does anybody else see this in VS.NET 2003?
If nobody else is getting this, what might I be doing to make it happen?
It's beginning to really irritate me.

Can you post a short test case that triggers the errors?

Tom
 
G

Guest

It took me a while to work this out but it's worth it because it's suggested
a work-around. Here's the example:

------
#include <iostream>

using std::blush:perator<<;

int main(int argc, char* argv[]) {
int x = f();
std::cout << "Hello" << std::endl;
}
------

There's a genuine error here at f() but that's followed by a spurious error
at the first <<. Delete the declaration of x and it compiles OK.

The culprit, if you haven't guessed already, is the using declaration for
operator<<. Remove that and the extra error disappears. It's unnecessary in
this case, and in many cases, because of argument-dependent lookup; I'll have
to experiment to see whether I can remove it generally from our code (we've
needed it in the past, given the range of compilers and platforms we build
on).

Rob
 
T

Tom Widmer [VC++ MVP]

rjd said:
It took me a while to work this out but it's worth it because it's suggested
a work-around. Here's the example:

------
#include <iostream>

using std::blush:perator<<;

int main(int argc, char* argv[]) {
int x = f();
std::cout << "Hello" << std::endl;
}

Unrelated to the bug, the above code is non-conforming (even with the
f() bit removed) - you need to
#include <ostream>
in order to use std::endl and non-members of basic_ostream, such as the
<< char const* overload that you are trying to call.
There's a genuine error here at f() but that's followed by a spurious error
at the first <<. Delete the declaration of x and it compiles OK.

The culprit, if you haven't guessed already, is the using declaration for
operator<<. Remove that and the extra error disappears. It's unnecessary in
this case, and in many cases, because of argument-dependent lookup; I'll have
to experiment to see whether I can remove it generally from our code (we've
needed it in the past, given the range of compilers and platforms we build
on).

I've confirmed the bug in VC7.1, but I don't have a VC8 beta installed
to see whether it has been fixed. Anyone?

Tom
 
H

Hendrik Schober

rjd said:
[...]
If nobody else is getting this, what might I be doing to make it happen?
It's beginning to really irritate me.

I know this, too, although I get it for other
stuff. In some of my files, whenever a syntax
error occurs, the compiler just freaks out and
throughs kilobytes of stupid errors at me after
the first one. Templates and overloads seem to
be in the pool of things that trigger this.
I got into the habit of fixing the first error
and just recompile if the next two messages do
not seem to make much sense to me. Yes, it's
annoying and it steals time. But C++ compilers
are hard to write and it's even harder to write
them so that they give good error messages. If
some particular message soesn't make any sense
to you, throw the code at Comeau -- its messages
are excellent (www.comeaucomputing.com/tryitout).


Schobi

--
(e-mail address removed) is never read
I'm Schobi at suespammers dot org

"Coming back to where you started is not the same as never leaving"
Terry Pratchett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top