[Bug c++/92687] New: decltype of a structured binding to a tuple component is a reference type inside a template function
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 #include template void foo() { auto [x, y] = std::tuple{0, 2}; static_assert(!std::is_reference::value); } void bar() { auto [x, y] = std::tuple{0, 2}; static_assert(!std::is_reference::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::value); | ^~
[Bug c++/85311] New: const& aggregate parameter with empty default brace initializer results in undefined references to std containers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85311 Bug ID: 85311 Summary: const& aggregate parameter with empty default brace initializer results in undefined references to std containers Product: gcc Version: 7.3.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 43890 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43890&action=edit preprocessed output Hello, The following code fails to link: --test.cpp-- #include struct Foo { std::vector x; }; void foo(const Foo& = {}) { } int main() { foo(); } --- $ g++ test.cpp /tmp/ccJsJY1c.o: In function `main': test.cpp:(.text+0x2a): undefined reference to `std::vector >::vector()' collect2: error: ld returned 1 exit status The problem is triggered by the default value for the parameter to foo(). It can be avoided by either changing the prototype of foo() to not have a default value, or by actually providing a value in the call to foo(). The same behavior occurs with several other std containers inside the aggregate such as deque and list. It can be reproduced in gcc versions 6.4.0, 7.2.0 and 7.3.0 and libstdc++ versions 6.0.22 and 6.0.24. The preprocessed file is attached. The output of g++ -v follows. Thank you, Vishal Output of "g++-7.3 -v -save-temps test.cpp" Using built-in specs. COLLECT_GCC=g++-7.3 COLLECT_LTO_WRAPPER=/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ./configure --enable-languages=c,c++ --prefix=/home/vishal/localbuild --program-suffix=-7.3 --disable-multilib Thread model: posix gcc version 7.3.0 (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/cc1plus -E -quiet -v -D_GNU_SOURCE test.cpp -mtune=generic -march=x86-64 -fpch-preprocess -o test.ii ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0 /home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/x86_64-pc-linux-gnu /home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward /home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include /home/vishal/localbuild/include /home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version -o test.s GNU C++14 (GCC) version 7.3.0 (x86_64-pc-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.0, MPFR version 3.1.3-p4, MPC version 1.0.2, isl version none warning: GMP header version 6.1.0 differs from library version 6.1.2. warning: MPFR header version 3.1.3-p4 differs from library version 3.1.6. warning: MPC header version 1.0.2 differs from library version 1.0.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++14 (GCC) version 7.3.0 (x86_64-pc-linux-gnu) compiled by GNU C version 7.3.0, GMP version 6.1.0, MPFR version 3.1.3-p4, MPC version 1.0.2, isl version none warning: GMP header version 6.1.0 differs from library version 6.1.2. warning: MPFR header version 3.1.3-p4 differs from library version 3.1.6. warning: MPC header version 1.0.2 differs from library version 1.0.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: e93c907a87f28f1e65d001f94ea5afa5 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' as -v --64 -o test.o test.s GNU assembler version 2.29.1 (x86_64-pc-linux-gnu) using BFD version (Gentoo 2.29.1 p3) 2.29.1 COMPILER_PATH=/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/:/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/:/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/:/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/7.3.0/:/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-gnu/ LIBRARY_PATH=/home/vishal/localbuild/lib/gcc/x86_64-pc-linux-g
[Bug c++/80935] New: [C++1z] incorrect error 'uninitialized variable in constexpr function' when conditionally declaring variable inside lambda inside template class
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80935 Bug ID: 80935 Summary: [C++1z] incorrect error 'uninitialized variable in constexpr function' when conditionally declaring variable inside lambda inside template class Product: gcc Version: 7.1.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 41445 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41445&action=edit preprocessed file generated by g++ -std=c++1z -v -save-temps The following code fails to compile with g++ 7.1.0 with flags -std=c++1z. It compiles with -std=c++14 or -std=c++11. I believe expected behavior is to compile cleanly. clang-4.0 also has no problem with this code. struct S { int x; int y; }; template struct Foo { void foo() { auto f = [](int x) { if (x) { S s; s.x = 20; s.y = 10; (void) s; } }; f(10); } }; int main() { Foo f; f.foo(); } When compiled with g++ -std=c++1z, the following error is raised: test.cpp: In instantiation of ‘Foo::foo():: [with T = int]’: test.cpp:26:15: required from ‘struct Foo::foo() [with T = int]::’ test.cpp:26:10: required from ‘void Foo::foo() [with T = int]’ test.cpp:45:9: required from here test.cpp:30:11: error: uninitialized variable ‘s’ in ‘constexpr’ function S s; ^ test.cpp:14:8: note: ‘struct S’ has no user-provided default constructor struct S ^ test.cpp:16:7: note: and the implicitly-defined constructor does not initialize ‘int S::x’ int x; The gcc build information is as follows: Using built-in specs. COLLECT_GCC=g++-7.1 COLLECT_LTO_WRAPPER=/home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ./configure --prefix=/home/vishal/localbuild --enable-languages=c,c++ --program-suffix=-7.1 --disable-multilib Thread model: posix gcc version 7.1.0 (GCC) COLLECT_GCC_OPTIONS='-std=c++1z' '-Wall' '-Wextra' '-v' '-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/vishal/localbuild/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -Wall -Wextra -std=c++1z -version -o test.s GNU C++14 (GCC) version 7.1.0 (x86_64-pc-linux-gnu) compiled by GNU C version 7.1.0, GMP version 6.1.0, MPFR version 3.1.3-p4, MPC version 1.0.2, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++14 (GCC) version 7.1.0 (x86_64-pc-linux-gnu) compiled by GNU C version 7.1.0, GMP version 6.1.0, MPFR version 3.1.3-p4, MPC version 1.0.2, isl version none GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072