Created attachment 1859668 [details] Small C++ program that reproduces this issue Description of problem: When compiling a compact reproducer program attached to this report, g++ reports “error: storing the address of local variable ‘…’ in ‘…’” even though it appears there is no way for the pointer to outlive its target. Version-Release number of selected component (if applicable): 12.0.1-0.6.fc36 How reproducible: Steps to Reproduce: 1. Compile repro.cpp (attached): g++ -O2 -g -Werror -Wall -o repro.o -c repro.cpp Actual results: In member function ‘where& where::operator=(where)’, inlined from ‘void array_where(where)’ at repro.cpp:19:10: repro.cpp:8:17: error: storing the address of local variable ‘array’ in ‘*sp.where::pointer’ [-Werror=dangling-pointer=] 8 | pointer = other.pointer; | ~~~~~~~~^~~~~~~~~~~~~~~ repro.cpp: In function ‘void array_where(where)’: repro.cpp:17:9: note: ‘array’ declared here 17 | int array[3] = { 0, 0, 0 }; | ^~~~~ repro.cpp:17:9: note: ‘sp’ declared here cc1plus: all warnings being treated as errors Expected results: No error. Additional info: This originally showed up in gsl-lite (bug 2045681).
Reproducer program as a comment: > struct where { > template< unsigned long N > > where(int (&arr)[N]) : pointer( &arr[0] ) {} > > where( where const & other ) : pointer( other.pointer ) {} > > where & operator=( where other ) { > pointer = other.pointer; > return *this; > } > > int * pointer; > }; > > void array_where(where sp) > { > int array[3] = { 0, 0, 0 }; > where sp2 = where( array ); > sp = sp2; > }
I've opened https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104436 in GCC Bugzilla to track this.
Thank you for the assistance in further reducing this and determining the exact nature of the bug.
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle. Changing version to 36.
This message is a reminder that Fedora Linux 36 is nearing its end of life. Fedora will stop maintaining and issuing updates for Fedora Linux 36 on 2023-05-16. It is Fedora's policy to close all bug reports from releases that are no longer maintained. At that time this bug will be closed as EOL if it remains open with a 'version' of '36'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, change the 'version' to a later Fedora Linux version. Note that the version field may be hidden. Click the "Show advanced fields" button if you do not see it. Thank you for reporting this issue and we are sorry that we were not able to fix it before Fedora Linux 36 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora Linux, you are encouraged to change the 'version' to a later version prior to this bug being closed.
Fedora Linux 36 entered end-of-life (EOL) status on 2023-05-16. Fedora Linux 36 is no longer maintained, which means that it will not receive any further security or bug fix updates. As a result we are closing this bug. If you can reproduce this bug against a currently maintained version of Fedora Linux please feel free to reopen this bug against that version. Note that the version field may be hidden. Click the "Show advanced fields" button if you do not see the version field. If you are unable to reopen this bug, please file a new report against an active release. Thank you for reporting this bug and we are sorry it could not be fixed.