[Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple

federico.reghenzani at polimi dot it gcc-bugzilla@gcc.gnu.org
Mon Jul 12 08:22:42 GMT 2021


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

            Bug ID: 101427
           Summary: std::get should refuse to compile if type is provided
                    and it is duplicated in std::tuple
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico.reghenzani at polimi dot it
  Target Milestone: ---

The following code should not compile:

----------------------------------------------------------
#include <tuple>

int main() {

        std::tuple<int, int> my_record;
        std::get<int>(my_record) = 10;

        return 0;
}
----------------------------------------------------------

Because `std::get<int>` accesses the `int` element which is duplicated. This is
not allowed by the standard: http://eel.is/c++draft/tuple#elem-5

Instead, it compiles and modifies only the first element in GCC 11.1.0 (while
it doesn't compile in 10.x.x). A full example here:
https://godbolt.org/z/YzorM9P8K

Expected behavior
-----------------
It should not compile and generate a compilation error.

Actual behavior
---------------
It compiles and (seems to) modify the first item of the tuple.


GCC Information
---------------
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/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++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (GCC)


More information about the Gcc-bugs mailing list