Bug 2051740 - Apparent false positive for -Wdangling-pointer
Summary: Apparent false positive for -Wdangling-pointer
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 36
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 2045681
TreeView+ depends on / blocked
 
Reported: 2022-02-07 22:50 UTC by Ben Beasley
Modified: 2023-05-25 16:51 UTC (History)
10 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2023-05-25 16:51:58 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Small C++ program that reproduces this issue (394 bytes, text/plain)
2022-02-07 22:50 UTC, Ben Beasley
no flags Details


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 104436 0 P3 NEW spurious -Wdangling-pointer assigning local address to a class passed by value 2022-02-07 23:52:04 UTC

Description Ben Beasley 2022-02-07 22:50:15 UTC
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).

Comment 1 Ben Beasley 2022-02-07 22:51:35 UTC
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;
> }

Comment 2 Martin Sebor 2022-02-07 23:52:05 UTC
I've opened https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104436 in GCC Bugzilla to track this.

Comment 3 Ben Beasley 2022-02-08 00:42:14 UTC
Thank you for the assistance in further reducing this and determining the exact nature of the bug.

Comment 4 Ben Cotton 2022-02-08 20:07:06 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 5 Ben Cotton 2023-04-25 16:53:41 UTC
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.

Comment 6 Ludek Smid 2023-05-25 16:51:58 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.