This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/86963] New: std::tuple incorrectly assigned


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86963

            Bug ID: 86963
           Summary: std::tuple incorrectly assigned
           Product: gcc
           Version: 8.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denin at mail dot ru
  Target Milestone: ---

$ cat meow.cpp 
#include <tuple>
#include <type_traits>

struct S {
        S &operator=(S const &) = delete;
        S &operator=(S &&) = delete;
};
static_assert(!std::is_move_assignable_v<std::tuple<S, S>>);

$ g++ meow.cpp 
meow.cpp:8:15: error: static assertion failed
 static_assert(!std::is_move_assignable_v<std::tuple<S, S>>);
               ^~~~

Despite tuple's elements being not assignable at all, tuple itself is
incorrectly considered assignable, due to non-SFINAE protected operator= in
class definition. Thus, the following code breaks on 'f = std::move(g);':

template<typename T> void mv_assign(T &left, T &&right) {
        if constexpr(std::is_move_assignable_v<std::tuple<S, S>>) left =
std::move(right);
}

int main() {
    std::tuple<S, S> f, g;
    mv_assign(f, std::move(g));
}

ENVIRONMENT

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --enable-multilib --disable-werror
--enable-checking=release --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 8.1.1 20180531 (GCC) 

$ uname -a
Linux home 4.17.10-1-ARCH #1 SMP PREEMPT Wed Jul 25 11:23:00 UTC 2018 x86_64
GNU/Linux

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]