From: Paolo Carlini Date: Tue, 3 Feb 2015 17:21:49 +0000 (+0000) Subject: re PR c++/64877 (strange warning message from -Waddress) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=457d0ace46de02afd84f2ed5bd333a72cb0f414f;p=gcc.git re PR c++/64877 (strange warning message from -Waddress) /cp 2015-02-03 Paolo Carlini PR c++/64877 * typeck.c (cp_build_binary_op): Avoid spurious -Waddress warnings for generated expressions. /testsuite 2015-02-03 Paolo Carlini PR c++/64877 * g++.dg/warn/Waddress-2.C: New. From-SVN: r220374 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7c200d629a2..60d7e676d95 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-02-03 Paolo Carlini + + PR c++/64877 + * typeck.c (cp_build_binary_op): Avoid spurious -Waddress warnings + for generated expressions. + 2015-02-02 Ville Voutilainen PR c++/64901 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 32ee78ec307..4c128b7ebe4 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4415,7 +4415,8 @@ cp_build_binary_op (location_t location, && decl_with_nonnull_addr_p (TREE_OPERAND (op0, 0))) { if ((complain & tf_warning) - && c_inhibit_evaluation_warnings == 0) + && c_inhibit_evaluation_warnings == 0 + && !TREE_NO_WARNING (op0)) warning (OPT_Waddress, "the address of %qD will never be NULL", TREE_OPERAND (op0, 0)); } @@ -4436,7 +4437,8 @@ cp_build_binary_op (location_t location, && decl_with_nonnull_addr_p (TREE_OPERAND (op1, 0))) { if ((complain & tf_warning) - && c_inhibit_evaluation_warnings == 0) + && c_inhibit_evaluation_warnings == 0 + && !TREE_NO_WARNING (op1)) warning (OPT_Waddress, "the address of %qD will never be NULL", TREE_OPERAND (op1, 0)); } @@ -4537,6 +4539,9 @@ cp_build_binary_op (location_t location, op1 = save_expr (op1); pfn0 = pfn_from_ptrmemfunc (op0); + /* Avoid -Waddress warnings (c++/64877). */ + if (TREE_CODE (pfn0) == ADDR_EXPR) + TREE_NO_WARNING (pfn0) = 1; pfn1 = pfn_from_ptrmemfunc (op1); delta0 = delta_from_ptrmemfunc (op0); delta1 = delta_from_ptrmemfunc (op1); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 335f2dad494..00c0450dbb5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,9 +1,14 @@ +2015-02-03 Paolo Carlini + + PR c++/64877 + * g++.dg/warn/Waddress-2.C: New. + 2015-02-03 Segher Boessenkool PR middle-end/61225 - gcc.target/i386/pr49095.c: XFAIL for ia32. + * gcc.target/i386/pr49095.c: XFAIL for ia32. -2015-02-03 +2015-02-03 Dodji Seketeli PR preprocessor/64803 * gcc.dg/cpp/builtin-macro-1.c: New test case. diff --git a/gcc/testsuite/g++.dg/warn/Waddress-2.C b/gcc/testsuite/g++.dg/warn/Waddress-2.C new file mode 100644 index 00000000000..58594f9629c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Waddress-2.C @@ -0,0 +1,24 @@ +// PR c++/64877 +// { dg-options "-Waddress" } + +template +struct S +{ + void m() { + } + + S() + { + if (&S::Unwrap != &Derived::Unwrap) + m(); + } + + void Unwrap() { + } +}; + +struct T : public S +{ +}; + +T t;