Opened 14 years ago

Closed 9 years ago

Last modified 9 years ago

#2839 closed Bugs (fixed)

move-emulated swap causes overloaded ambiguous fun call

Reported by: st@… Owned by: Antony Polukhin
Milestone: Boost 1.56.0 Component: variant
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

The attached test file is a minimal example of something I have a real-world use for (with T instead of int), and it doesn't compile in MS Visual Studio 2005 or 2008. The error message is too long as it's templated code, but the head follows: 1>c:\Users\dh\products\avir\include\boost/variant/detail/move.hpp(155) : error C2668: 'boost::detail::variant::detail::move_swap::swap' : ambiguous call to overloaded function 1> c:\Users\dh\products\avir\include\boost/variant/detail/move.hpp(141): could be 'void boost::detail::variant::detail::move_swap::swap<T>(T &,T &)' 1> with 1> [ 1> T=T2 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\utility(16): or 'void std::swap<T>(_Ty &,_Ty &)' [found using argument-dependent lookup] 1> with 1> [ 1> T=T2, 1> _Ty=T2 1> ] 1> while trying to match the argument list '(T2 , T2 )' 1> c:\Users\dh\products\avir\include\boost/variant/variant.hpp(684) : see reference to function template instantiation 'void boost::detail::variant::move_swap<T>(T &,T &)' being compiled 1> with 1> [ 1> T=T2 1> ]

The crucial code is in variant/detail/move.hpp, from line 114. As my variant includes a std::vector<T>*, it finds std::swap in the unqualified call on line 155.

The code in question is protected by a BOOST_WORKAROUND that disables it for gcc. I tested this case on gcc, and it works fine, but fails in the same way if I remove the workaround. The comment above it claims that it falls back for "non-conforming compilers," but I'm not convinced that the expected behaviour is conformant. Basic.lookup.koenig says explicitly that "If T is a pointer to U or an array of U, its associated namespaces and classes are those associated with U."

Attachments (3)

variant-test.cpp (308 bytes ) - added by st@… 14 years ago.
small test program
msvc-output.txt (6.2 KB ) - added by st@… 14 years ago.
MSVC output
variant-test.diff (1.6 KB ) - added by st@… 13 years ago.
patch adding test case to variant's unit tests

Download all attachments as: .zip

Change History (11)

by st@…, 14 years ago

Attachment: variant-test.cpp added

small test program

by st@…, 14 years ago

Attachment: msvc-output.txt added

MSVC output

comment:1 by st@…, 14 years ago

Since the error message got wrapped anyway, I've added the whole output as an attachment.

by st@…, 13 years ago

Attachment: variant-test.diff added

patch adding test case to variant's unit tests

comment:2 by Joseph.Gauterin, 13 years ago

We solved a similar problem in Boost.Swap by providing a templated swap with two template arguments [making it less specialized than std::swap]. I've had a quick look at variant/detail/move.hpp and I think it can be fixed in the same way.

comment:3 by Laurent.Rineau@…, 9 years ago

The bug is still in Boost 1.53. Could a maintainer of Boost.Variant have a look at the test case and the proposed patch?

comment:4 by Antony Polukhin, 9 years ago

(In [85927]) Optimize and fix ambiguity of move_swap in Boost.Variant (refs #2839) Fix GCC-4.8+ warning in variant_reference_test.cpp

comment:5 by Antony Polukhin, 9 years ago

Owner: changed from ebf to Antony Polukhin
Status: newassigned

comment:6 by Antony Polukhin, 9 years ago

(In [86049]) Commit missing test file for Boost.Variant and uncomment line in Jamfile (refs #2839)

comment:7 by Antony Polukhin, 9 years ago

Resolution: fixed
Status: assignedclosed

(In [86650]) Merge from trunk:

  • dropped support of antique compilers
  • fixed issue with ambiguity in swap (fixes #2839)
  • added conditional noexcepts to move assignments, default and move constructors (fixes #7911)
  • experimental variadic templates support (refs #9163)
  • bunch of size optimizations for assignments and move assignments (refs #7960)
  • minor changes and size optimizations

comment:8 by Antony Polukhin, 9 years ago

Milestone: Boost 1.39.0Boost 1.56.0
Note: See TracTickets for help on using tickets.