A
Alf P. Steinbach
Comeau compiles fine, g++ and msvc fail.
<code file="x.cpp">
#include <algorithm>
namespace adl_is_bad {
struct Foo
{
friend void swap( Foo&, Foo& ) {}
};
struct Bar
{
Foo myFoo;
int myInt;
Bar(): myInt( 0 ) {}
friend void swap( Bar& a, Bar& b )
{
using namespace std;
//sswap( a.myFoo, b.myFoo );
swap( a.myInt, b.myInt );
}
};
} // namespace adl_is_bad
int main() {}
</code>
<comeau>
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
In strict mode, with -tused, Compile succeeded (but remember, the Comeau online
compiler does not link).
Compiled with C++0x extensions enabled.
</comeau>
<g++ 4.4.1>
C:\test> gnuc --version
g++ (TDM-2 mingw32) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\test> gnuc x.cpp
x.cpp: In function 'void adl_is_bad::swap(adl_is_bad::Bar&, adl_is_bad::Bar&)':
x.cpp:21: error: 'swap' was not declared in this scope
C:\test> _
</g++ 4.4.1>
<msvc 7.1>
C:\test> msvc --version
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\test> msvc x.cpp
x.cpp
x.cpp(21) : error C3767: 'swap' matching function is not accessible
could be the friend function at 'x.cpp(7)' : 'swap' [may be found via
argument-dependent lookup]
or the friend function at 'x.cpp(17)' : 'swap' [may be found via
argument-dependent lookup]
C:\test> _
</msvc 7.1>
<msvc 9.0>
C:\test> msvc --version
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\test> msvc x.cpp
x.cpp
x.cpp(21) : error C2664: 'void adl_is_bad::swap(adl_is_bad::Bar
&,adl_is_bad::Bar &)' : cannot convert parameter 1 from
'int' to 'adl_is_bad::Bar &'
C:\test> _
</msvc 9.0>
Which compiler is right, if any?
Is there a commonly used solution for this?
Or perhaps, just a solution?
Cheers,
- Alf
<code file="x.cpp">
#include <algorithm>
namespace adl_is_bad {
struct Foo
{
friend void swap( Foo&, Foo& ) {}
};
struct Bar
{
Foo myFoo;
int myInt;
Bar(): myInt( 0 ) {}
friend void swap( Bar& a, Bar& b )
{
using namespace std;
//sswap( a.myFoo, b.myFoo );
swap( a.myInt, b.myInt );
}
};
} // namespace adl_is_bad
int main() {}
</code>
<comeau>
Your Comeau C/C++ test results are as follows:
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
In strict mode, with -tused, Compile succeeded (but remember, the Comeau online
compiler does not link).
Compiled with C++0x extensions enabled.
</comeau>
<g++ 4.4.1>
C:\test> gnuc --version
g++ (TDM-2 mingw32) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\test> gnuc x.cpp
x.cpp: In function 'void adl_is_bad::swap(adl_is_bad::Bar&, adl_is_bad::Bar&)':
x.cpp:21: error: 'swap' was not declared in this scope
C:\test> _
</g++ 4.4.1>
<msvc 7.1>
C:\test> msvc --version
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\test> msvc x.cpp
x.cpp
x.cpp(21) : error C3767: 'swap' matching function is not accessible
could be the friend function at 'x.cpp(7)' : 'swap' [may be found via
argument-dependent lookup]
or the friend function at 'x.cpp(17)' : 'swap' [may be found via
argument-dependent lookup]
C:\test> _
</msvc 7.1>
<msvc 9.0>
C:\test> msvc --version
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
usage: cl [ option... ] filename... [ /link linkoption... ]
C:\test> msvc x.cpp
x.cpp
x.cpp(21) : error C2664: 'void adl_is_bad::swap(adl_is_bad::Bar
&,adl_is_bad::Bar &)' : cannot convert parameter 1 from
'int' to 'adl_is_bad::Bar &'
C:\test> _
</msvc 9.0>
Which compiler is right, if any?
Is there a commonly used solution for this?
Or perhaps, just a solution?
Cheers,
- Alf