#2839 closed Bugs (fixed)
move-emulated swap causes overloaded ambiguous fun call
Reported by: | 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)
Change History (11)
by , 14 years ago
Attachment: | variant-test.cpp added |
---|
comment:1 by , 14 years ago
Since the error message got wrapped anyway, I've added the whole output as an attachment.
by , 13 years ago
Attachment: | variant-test.diff added |
---|
patch adding test case to variant's unit tests
comment:2 by , 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 , 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 , 9 years ago
comment:5 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:6 by , 9 years ago
comment:7 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(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 , 9 years ago
Milestone: | Boost 1.39.0 → Boost 1.56.0 |
---|
small test program