std::experimental::optional::swap() vs std::swap()

Avi Kivity
Sat Apr 22 19:24:00 GMT 2017

libstdc++'s optional::swap reads as follows:

       swap(optional& __other)
                && 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 

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())
         else if (__other._M_is_engaged())

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?

More information about the Gcc-help mailing list