public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anabelsmruggiero at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/105976] New: -Wuse-after-free warning with std::shared_ptr<std::shared_ptr<T>[]>::reset
Date: Tue, 14 Jun 2022 16:17:28 +0000	[thread overview]
Message-ID: <bug-105976-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2022-06-14 16:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 16:17 anabelsmruggiero at gmail dot com [this message]
2022-06-15  9:08 ` [Bug c++/105976] " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105976-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).