public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/108554] New: Warning "null pointer dereferece" raised when extracting a unique_ptr from a map and any "-O" flag
@ 2023-01-26  9:13 fcontact at cuveland dot de
  2023-01-26  9:51 ` [Bug libstdc++/108554] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: fcontact at cuveland dot de @ 2023-01-26  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108554
           Summary: Warning "null pointer dereferece" raised when
                    extracting a unique_ptr from a map and any "-O" flag
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fcontact at cuveland dot de
  Target Milestone: ---

I found what I believe might be a false positive with g++ 12 when using the
"-Wnull-dereference" warning and a map of unique_ptr with any level of
optimisation.

This behavior does not show up in GCC 9, 10, and 11.

Small but complete example:

#include <map>
#include <memory>
#include <string>
#include <utility>

int main()
{
  // create and initialize a map
  std::map<std::string, std::unique_ptr<int>> my_map;
  my_map["my_key"] = std::make_unique<int>(1);

  auto it = my_map.find("my_key");
  if (it != my_map.end()) {
    // extract an item from the map
    auto item = std::move(my_map.extract(it).mapped());
    return *item;
  }
  return 0;
}

Compiled with:
g++-12 -O -Wnull-dereference <filename>

Compiler version:
g++ (Compiler-Explorer-Build-gcc--binutils-2.38) 12.2.0
(see https://godbolt.org/z/E9KhTT4f6)

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

end of thread, other threads:[~2023-03-28 23:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26  9:13 [Bug libstdc++/108554] New: Warning "null pointer dereferece" raised when extracting a unique_ptr from a map and any "-O" flag fcontact at cuveland dot de
2023-01-26  9:51 ` [Bug libstdc++/108554] " redi at gcc dot gnu.org
2023-01-26  9:56 ` fcontact at cuveland dot de
2023-01-26 10:11 ` redi at gcc dot gnu.org
2023-01-26 10:14 ` redi at gcc dot gnu.org
2023-01-26 13:38 ` cvs-commit at gcc dot gnu.org
2023-01-26 13:41 ` [Bug libstdc++/108554] [12 Regression] " redi at gcc dot gnu.org
2023-01-27 15:43 ` cvs-commit at gcc dot gnu.org
2023-03-28 23:35 ` cvs-commit at gcc dot gnu.org
2023-03-28 23:35 ` redi 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).