public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95589] New: missing warning initializing a reference with a dereferenced null
@ 2020-06-08 19:25 msebor at gcc dot gnu.org
  2020-06-08 19:29 ` [Bug c++/95589] " msebor at gcc dot gnu.org
  2021-08-13  8:13 ` egallager at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-08 19:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95589
           Summary: missing warning initializing a reference with a
                    dereferenced null
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Initializing a reference by dereferenced null pointer is not diagnosed but
should be because such a reference is invalid:

$ cat t.C && gcc -O2 -S -Wall -Wextra -Wnull-dereference
-fdump-tree-optimized=/dev/stdout t.C
void f (const int&);
void g ()
{
  int *p = 0;
  f (*p);
}

;; Function g (_Z1gv, funcdef_no=0, decl_uid=2330, cgraph_uid=1,
symbol_order=0)

g ()
{
  <bb 2> [local count: 1073741824]:
  f (0B); [tail call]
  return;

}

Clang doesn't diagnose it either unless --analyze is used:

$ clang -S -Wall -Wextra --analyze t.C
t.C:5:3: warning: Forming reference to null pointer
  f (*p);
  ^~~~~~
1 warning generated.

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

* [Bug c++/95589] missing warning initializing a reference with a dereferenced null
  2020-06-08 19:25 [Bug c++/95589] New: missing warning initializing a reference with a dereferenced null msebor at gcc dot gnu.org
@ 2020-06-08 19:29 ` msebor at gcc dot gnu.org
  2021-08-13  8:13 ` egallager at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-08 19:29 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=84316
             Blocks|                            |86172
           Keywords|                            |diagnostic

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I was about to classify this as an enhancement but after reading the
description of -Wnull-dereference in the manual ("compiler detects paths that
trigger erroneous or undefined behavior due to dereferencing a null pointer")
I'm inclined to view it as a bug.  The code is clearly in error, GCC just
doesn't detect it (even though the "doesn't detect it" part could be used to
argue the warning works strictly as documented).


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86172
[Bug 86172] [meta-bug] issues with -Wnull-dereference

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

* [Bug c++/95589] missing warning initializing a reference with a dereferenced null
  2020-06-08 19:25 [Bug c++/95589] New: missing warning initializing a reference with a dereferenced null msebor at gcc dot gnu.org
  2020-06-08 19:29 ` [Bug c++/95589] " msebor at gcc dot gnu.org
@ 2021-08-13  8:13 ` egallager at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-08-13  8:13 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-13
                 CC|                            |egallager at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2021-08-13  8:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-08 19:25 [Bug c++/95589] New: missing warning initializing a reference with a dereferenced null msebor at gcc dot gnu.org
2020-06-08 19:29 ` [Bug c++/95589] " msebor at gcc dot gnu.org
2021-08-13  8:13 ` egallager 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).