public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103363] New: confusing -Wnonnull-compare testing a reference argument for equality to null
@ 2021-11-22 17:43 msebor at gcc dot gnu.org
  2021-11-22 17:44 ` [Bug c++/103363] " msebor at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-11-22 17:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103363
           Summary: confusing -Wnonnull-compare testing a reference
                    argument for equality to null
           Product: gcc
           Version: 4.2.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: ---

Since the conversion of the address of a reference to bool is diagnosed by
-Waddress, issuing a second warning for it isn't necessary.  Mentioning
attribute nonnull where there is one in the source code seems confusing.

$ cat t.C && gcc -O2 -S -Wall t.C
struct S { int i; };

bool f (const S &s)
{
  return &s;
}
t.C: In function ‘bool f(const S&)’:
t.C:5:10: warning: the compiler can assume that the address of ‘s’ will never
be NULL [-Waddress]
    5 |   return &s;
      |          ^~
t.C:3:18: note: ‘s’ declared here
    3 | bool f (const S &s)
      |         ~~~~~~~~~^
t.C:5:11: warning: ‘nonnull’ argument ‘s’ compared to NULL [-Wnonnull-compare]
    5 |   return &s;
      |           ^


Clang issues just one warning (though the wording doesn't seem ideal either:
there's no evidence of dereferencing a null pointer so assuming that's what
necessarily led the programmer to the test doesn't seem warranted):
warning: reference cannot be bound to dereferenced null pointer in well-defined
C++ code; pointer may be assumed to always convert to true
[-Wundefined-bool-conversion]
  return &s;

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

* [Bug c++/103363] confusing -Wnonnull-compare testing a reference argument for equality to null
  2021-11-22 17:43 [Bug c++/103363] New: confusing -Wnonnull-compare testing a reference argument for equality to null msebor at gcc dot gnu.org
@ 2021-11-22 17:44 ` msebor at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-11-22 17:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.3.0, 11.2.0, 12.0,
                   |                            |6.5.0, 7.5.0, 8.5.0, 9.3.0
           Keywords|                            |diagnostic

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Both warnings started to be issued in GCC 6.

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

end of thread, other threads:[~2021-11-22 17:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 17:43 [Bug c++/103363] New: confusing -Wnonnull-compare testing a reference argument for equality to null msebor at gcc dot gnu.org
2021-11-22 17:44 ` [Bug c++/103363] " msebor 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).