From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 11BA23959C80; Thu, 8 Apr 2021 21:28:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11BA23959C80 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/86879] G++ should warn about redundant tests for null pointers returned from functions with __attribute__((returns_nonnull)) Date: Thu, 08 Apr 2021 21:28:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Apr 2021 21:28:44 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D86879 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2018-08-07 00:00:00 |2021-4-8 --- Comment #2 from Martin Sebor --- No progress in GCC 11. Clang issues -Wpointer-bool-conversion and -Wundefined-bool-conversion: cat pr86879.C && clang -S -Wall pr86879.C void* get() __attribute__((returns_nonnull)); int f() { return get() ? 0 : 1; } int& ref(); int g() { return &ref() ? 0 : 1; } pr86879.C:3:18: warning: nonnull function call 'get()' will evaluate to 'tr= ue' on first encounter [-Wpointer-bool-conversion] int f() { return get() ? 0 : 1; } ^~~~~ ~ pr86879.C:1:28: note: declared 'returns_nonnull' here void* get() __attribute__((returns_nonnull)); ^ pr86879.C:9:11: warning: reference cannot be bound to dereferenced null poi= nter in well-defined C++ code; pointer may be assumed to always convert to true [-Wundefined-bool-conversion] return &ref() ? 0 : 1; ^~~~~ ~ pr86879.C:5:6: note: 'ref' returns a reference int& ref(); ^ 2 warnings generated.=