public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "vries at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug build/30413] [gdb/build] error: storing the address of local variable ‘<anonymous>’ in ‘frame_info_ptr::frame_list.intrusive_list<frame_info_ptr>::m_back’ [-Werror=dangling-pointer=]
Date: Wed, 03 May 2023 10:07:27 +0000	[thread overview]
Message-ID: <bug-30413-4717-F1vZSOHbqJ@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30413-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=30413

--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
FWIW, I've managed to reproduce this outside of the gdb build, while using
gdbsupport/intrusive_list.h:
...
$ cat test.C
#include <iterator>

#include <assert.h>
#define gdb_assert(A) assert (A)

#include "src/gdbsupport/intrusive_list.h"

class void_ptr;

class void_ptr : public intrusive_list_node<void_ptr>
{
public:
  void_ptr () : m_ptr (nullptr) {
    void_ptr_list.push_back (*this);
  }

  void_ptr (const void_ptr &other) : m_ptr (other.m_ptr)
  {
    void_ptr_list.push_back (*this);
  }

  ~void_ptr ()
  {
    if (is_linked ())
      void_ptr_list.erase (void_ptr_list.iterator_to (*this));
  }

private:
  mutable void *m_ptr = nullptr;
  static intrusive_list<void_ptr> void_ptr_list;
};

intrusive_list<void_ptr> void_ptr::void_ptr_list;

void 
bar (void_ptr arg)
{

}

void
foo (void_ptr arg)
{
  bar (arg);
}

int
main (void)
{
  void_ptr ptr_to_a;
  foo (ptr_to_a);

  return 0;
}
...

With -Wdangling-pointer=0:
...
$ g++ test.C -Wdangling-pointer=0 -pedantic -O1 -g -Werror
$
...

With -Wdangling-pointer=1:
...
$ g++ test.C -Wdangling-pointer=1 -pedantic -O1 -g -Werror
In file included from test.C:6:
In member function ‘void intrusive_list<T, AsNode>::push_empty(T&) [with T =
void_ptr; AsNode = intrusive_base_node<void_ptr>]’,
    inlined from ‘void intrusive_list<T, AsNode>::push_back(reference) [with T
= void_ptr; AsNode = intrusive_base_node<void_ptr>]’ at
src/gdbsupport/intrusive_list.h:332:24,
    inlined from ‘void_ptr::void_ptr(const void_ptr&)’ at test.C:19:29,
    inlined from ‘void foo(void_ptr)’ at test.C:44:7:
src/gdbsupport/intrusive_list.h:415:12: error: storing the address of local
variable ‘<anonymous>’ in
‘void_ptr::void_ptr_list.intrusive_list<void_ptr>::m_back’
[-Werror=dangling-pointer=]
  415 |     m_back = &elem;
      |     ~~~~~~~^~~~~~~
test.C: In function ‘void foo(void_ptr)’:
test.C:44:7: note: ‘<anonymous>’ declared here
   44 |   bar (arg);
      |   ~~~~^~~~~
test.C:33:26: note: ‘void_ptr::void_ptr_list’ declared here
   33 | intrusive_list<void_ptr> void_ptr::void_ptr_list;
      |                          ^~~~~~~~
cc1plus: all warnings being treated as errors
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-05-03 10:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-02 16:57 [Bug build/30413] New: " vries at gcc dot gnu.org
2023-05-02 16:59 ` [Bug build/30413] " vries at gcc dot gnu.org
2023-05-02 20:48 ` tromey at sourceware dot org
2023-05-02 20:52 ` mark at klomp dot org
2023-05-02 20:54 ` mark at klomp dot org
2023-05-03 10:07 ` vries at gcc dot gnu.org [this message]
2023-05-03 10:49 ` vries at gcc dot gnu.org
2023-05-03 10:49 ` vries at gcc dot gnu.org
2023-05-03 13:56 ` simon.marchi at polymtl dot ca
2023-05-03 15:11 ` cvs-commit at gcc dot gnu.org
2023-05-03 15:43 ` mark at klomp dot org
2023-05-03 16:40 ` vries at gcc dot gnu.org
2023-05-03 16:53 ` simon.marchi at polymtl dot ca
2023-05-03 18:00 ` vries at gcc dot gnu.org
2023-05-03 19:43 ` cvs-commit at gcc dot gnu.org
2023-05-03 19:56 ` vries at gcc dot gnu.org
2023-05-03 20:15 ` vries 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-30413-4717-F1vZSOHbqJ@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.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).