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

            Bug ID: 92687
           Summary: decltype of a structured binding to a tuple component
                    is a reference type inside a template function
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vis...@royal-caliber.com
  Target Milestone: ---

Created attachment 47370
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47370&action=edit
preprocessed file

Hello,

The code below shows an inconsistency in the handling of decltype for
structured bindings within template functions vs. non-template functions - the
static_assert in foo() triggers, but not in bar(). I think the handling in
bar() is correct, as per the notes at
https://en.cppreference.com/w/cpp/language/structured_binding.

This may or may not be related to bug 81176. Details of the compilation command
are listed below the source.

Thank you,
Vishal

------------------------------------------------------------

#include <type_traits>
#include <tuple>

template <bool b = false>
void foo()
{
  auto [x, y] = std::tuple<int, int>{0, 2};
  static_assert(!std::is_reference<decltype(x)>::value);
}

void bar()
{
  auto [x, y] = std::tuple<int, int>{0, 2};
  static_assert(!std::is_reference<decltype(x)>::value);
}

int main()
{
  foo<>();
  bar();
}

-----------------------------------------------------------

g++-9.2.0 -v -save-temps -pedantic -Wall -Wextra -std=c++17 test.cpp
Using built-in specs.
COLLECT_GCC=g++-9.2.0
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-9.2.0/work/gcc-9.2.0/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/9.2.0
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 9.2.0 p1' --disable-esp --enable-libstdcxx-time
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --disable-multilib --with-multilib-list=m64
--disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp
--disable-libmudflap --disable-libssp --disable-systemtap
--enable-vtable-verify --enable-lto --without-isl --enable-default-pie
--enable-default-ssp
Thread model: posix
gcc version 9.2.0 (Gentoo 9.2.0 p1) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wpedantic' '-Wall' '-Wextra'
'-std=c++17' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/cc1plus -E -quiet -v -D_GNU_SOURCE
test.cpp -mtune=generic -march=x86-64 -std=c++17 -Wpedantic -Wall -Wextra
-fpch-preprocess -o test.ii
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/x86_64-pc-linux-gnu
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/backward
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wpedantic' '-Wall' '-Wextra'
'-std=c++17' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/cc1plus -fpreprocessed test.ii
-quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -Wpedantic
-Wall -Wextra -std=c++17 -version -o test.s
GNU C++17 (Gentoo 9.2.0 p1) version 9.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 3.1.6,
MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++17 (Gentoo 9.2.0 p1) version 9.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 3.1.6,
MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 2f11227cf3606c8ecdab2bd17fc2bf18
test.cpp: In function ‘void foo()’:
test.cpp:9:17: error: static assertion failed
    9 |   static_assert(!std::is_reference<decltype(x)>::value);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to