On 11/22/21 18:21, Marek Polacek wrote:
On Mon, Nov 22, 2021 at 04:00:56PM -0700, Martin Sebor via Gcc-patches wrote:
While going through old -Waddress bug reports to close after
the recent improvements to the warning I came across PR 96507
that points out that member references aren't handled. Since
testing the address of a reference for equality to null is
in general diagnosed, this seems like an oversight worth fixing.
Attached is a change to the C++ front end to diagnose member
references as well.
Tested on x86_64-linux.
Martin
Issue -Waddress also for reference members [PR96507].
Resolves:
PR c++/96507 - missing -Waddress for member references
gcc/cp/ChangeLog:
PR c++/96507
* typeck.c (warn_for_null_address): Handle reference members.
gcc/testsuite/ChangeLog:
PR c++/96507
* g++.dg/warn/Waddress-8.C: New test.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 58919aaf13e..694c53eef8a 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4676,15 +4676,21 @@ warn_for_null_address (location_t location, tree op,
tsubst_flags_t complain)
"addition %qE and NULL", cop);
return;
}
- else if (CONVERT_EXPR_P (op)
- && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (op, 0))))
+ else if (CONVERT_EXPR_P (op))
{
- STRIP_NOPS (op);
+ tree op0 = TREE_OPERAND (op, 0);
+ if (TYPE_REF_P (TREE_TYPE (op0)))
+ {
Isn't this just REFERENCE_REF_P?
No, there's no INDIRECT_REF here.
Martin, I think you don't need to change the test to two levels since
you don't use the op0 variable again; I think these two lines:
+ if (TREE_CODE (op) == COMPONENT_REF)
+ op = TREE_OPERAND (op, 1);
are all the change you need for this fix. OK that way.
Jason