#include <initializer_list> #include <string> struct X { X(std::initializer_list<std::string>, int) { } }; int main() { X x( {"", "", "", ""}, 1|4 ); return 0; } tmp$ g++ -g debug.C -o debug tmp$ gdb -q debug Reading symbols from debug... (gdb) start Temporary breakpoint 1 at 0x40123a: file debug.C, line 12. Starting program: /tmp/debug [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Temporary breakpoint 1, main () at debug.C:12 12 } (gdb) n 10 X x( {"", "", "", ""}, 1|4 ); (gdb) 12 } (gdb) 11 return 0; (gdb) __libc_start_call_main (main=main@entry=0x401226 <main()>, argc=argc@entry=1, argv=argv@entry=0x7fffffffd7a8) at ../sysdeps/nptl/libc_start_call_main.h:74 74 exit (result); (gdb) [Inferior 1 (process 577012) exited normally] Why does "start" break on the closing brace of main(), and then the construction of 'x' also jumps to the closing brace? In less trivial examples I've seen it jump back and forth multiple times: 243 libmap libs; (gdb) n 245 redi::ipstream in({"ldd", argv[arg]}, pstdout|pstderr); (gdb) 310 } (gdb) 245 redi::ipstream in({"ldd", argv[arg]}, pstdout|pstderr); (gdb) 310 } (gdb) 245 redi::ipstream in({"ldd", argv[arg]}, pstdout|pstderr); (gdb) [Detaching after fork from child process 845854] 310 } (gdb)
This is with the Fedora packages but I see it with GCC trunk too. $ rpm -q gcc gdb gcc-12.2.1-2.fc36.x86_64 gdb-12.1-1.fc36.x86_64
I think there is another bug about this one ...
It started with r12-6329 c++: EH and partially constructed aggr temp [PR66139]
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:ce3a1b5976079b1467473b4628f05797fd2eae08 commit r13-3072-gce3a1b5976079b1467473b4628f05797fd2eae08 Author: Jason Merrill <jason@redhat.com> Date: Tue Oct 4 17:06:04 2022 -0400 c++: fix debug info for array temporary [PR107154] In the testcase the elaboration of the array init that happens at genericize time was getting the location info for the end of the function; fixed by doing the expansion at the location of the original expression. PR c++/107154 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_genericize_init_expr): Use iloc_sentinel. (cp_genericize_target_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/debug/dwarf2/lineno-array1.C: New test.
The releases/gcc-12 branch has been updated by Jason Merrill <jason@gcc.gnu.org>: https://gcc.gnu.org/g:2088358b658c44f69d37af0d7deec321f557741d commit r12-9430-g2088358b658c44f69d37af0d7deec321f557741d Author: Jason Merrill <jason@redhat.com> Date: Tue Oct 4 17:06:04 2022 -0400 c++: fix debug info for array temporary [PR107154] In the testcase the elaboration of the array init that happens at genericize time was getting the location info for the end of the function; fixed by doing the expansion at the location of the original expression. PR c++/107154 gcc/cp/ChangeLog: * cp-gimplify.cc (cp_genericize_init_expr): Use iloc_sentinel. (cp_genericize_target_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/debug/dwarf2/lineno-array1.C: New test.
Fixed for 12.3/13.