On 22 April 2017 at 21:34, Jonathan Wakely <jwakely.gcc@xxxxxxxxx> wrote: > On 22 April 2017 at 20:24, Avi Kivity wrote: >> libstdc++'s optional::swap reads as follows: >> >> >> void >> swap(optional& __other) >> noexcept(is_nothrow_move_constructible<_Tp>() >> && noexcept(swap(declval<_Tp&>(), declval<_Tp&>()))) >> { >> >> >> When compiling with clang, it complains that swap() (called from the >> noexcept operator) accepts only one argument. Isn't it correct? shouldn't >> single-argument member swap() hide the two-argument non-member swap? >> >> >> A few lines below, libstdc++ continues: >> >> >> using std::swap; >> >> if (this->_M_is_engaged() && __other._M_is_engaged()) >> swap(this->_M_get(), __other._M_get()); >> else if (this->_M_is_engaged()) >> { >> __other._M_construct(std::move(this->_M_get())); >> this->_M_destruct(); >> } >> else if (__other._M_is_engaged()) >> { >> this->_M_construct(std::move(__other._M_get())); >> __other._M_destruct(); >> } >> } >> >> So it's explicitly bringing std::swap into scope here, but it's too late for >> the expression in the noexcept operator. >> >> >> Is this a bug in libstdc++ (and in gcc for not detecting it), or in clang? > > Yes, it's a libstdc++ bug, similar to > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63860 > > It's a G++ bug for not detecting it (we do lookup in exception > specifications incorrectly). > > We have __is_nothrow_swappable now, so should be using that there, > could you report it to bugzilla please? The fix is: --- a/libstdc++-v3/include/experimental/optional +++ b/libstdc++-v3/include/experimental/optional @@ -690,7 +690,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void swap(optional& __other) noexcept(is_nothrow_move_constructible<_Tp>() - && noexcept(swap(declval<_Tp&>(), declval<_Tp&>()))) + && __is_nothrow_swappable<_Tp>::value) { using std::swap;