public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105976] New: -Wuse-after-free warning with std::shared_ptr<std::shared_ptr<T>[]>::reset
@ 2022-06-14 16:17 anabelsmruggiero at gmail dot com
  2022-06-15  9:08 ` [Bug c++/105976] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: anabelsmruggiero at gmail dot com @ 2022-06-14 16:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105976
           Summary: -Wuse-after-free warning with
                    std::shared_ptr<std::shared_ptr<T>[]>::reset
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anabelsmruggiero at gmail dot com
  Target Milestone: ---

GCC 12.1 emits a use-after-free warning when calling
std::shared_ptr<std::shared_ptr<T>[]>::reset outside of main:


void testArrOfArr(){
    std::shared_ptr<std::shared_ptr< double[] >[]> testPtr; 
    testPtr.reset(new std::shared_ptr< double[] >[6]);
}

void testArr(){
    std::shared_ptr<std::shared_ptr< double >[]> testPtr; 
    testPtr.reset(new std::shared_ptr< double >[6]);
}

int main(){
    // Uncommenting the body of main squelches all warnings
    /*
    std::shared_ptr<std::shared_ptr< double >[]> testArrPtr;
    testArrPtr.reset(new std::shared_ptr< double >[6]);

    std::shared_ptr<std::shared_ptr< double[] >[]> testArrOfArrPtr;
    testArrOfArrPtr.reset(new std::shared_ptr< double[] >[6]);
    */
}

Compiler arguments: -std=c++20 -Wall -Wextra -O2 
This warning occurs at or above -02 and disappears below that.

I also have this repro on Godbolt with a few more additional lines that end up
squelching the warning: https://godbolt.org/z/YaKP985es

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/105976] -Wuse-after-free warning with std::shared_ptr<std::shared_ptr<T>[]>::reset
  2022-06-14 16:17 [Bug c++/105976] New: -Wuse-after-free warning with std::shared_ptr<std::shared_ptr<T>[]>::reset anabelsmruggiero at gmail dot com
@ 2022-06-15  9:08 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-06-15  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think I've seen a duplicate for this.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-15  9:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-14 16:17 [Bug c++/105976] New: -Wuse-after-free warning with std::shared_ptr<std::shared_ptr<T>[]>::reset anabelsmruggiero at gmail dot com
2022-06-15  9:08 ` [Bug c++/105976] " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).