From 739745618a4202f3bf515494175eacae6ff05d2d Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Thu, 8 Feb 2018 18:54:39 +0000 Subject: [PATCH] re PR c++/83806 (Spurious -Wunused-but-set-parameter with nullptr) /cp 2018-02-08 Paolo Carlini PR c++/83806 * typeck.c (decay_conversion): Use mark_rvalue_use for the special case of nullptr too. /testsuite 2018-02-08 Paolo Carlini PR c++/83806 * g++.dg/warn/Wunused-parm-11.C: New. From-SVN: r257502 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 5 ++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Wunused-parm-11.C | 13 +++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-parm-11.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2fc35d2dea1..c68b590a295 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-02-08 Paolo Carlini + + PR c++/83806 + * typeck.c (decay_conversion): Use mark_rvalue_use for the special + case of nullptr too. + 2018-02-08 Nathan Sidwell * class.c (finish_struct): Fix std:initializer_list diagnostic diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 83e76782998..fe18ea9d16a 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2009,7 +2009,10 @@ decay_conversion (tree exp, return error_mark_node; if (NULLPTR_TYPE_P (type) && !TREE_SIDE_EFFECTS (exp)) - return nullptr_node; + { + mark_rvalue_use (exp, loc, reject_builtin); + return nullptr_node; + } /* build_c_cast puts on a NOP_EXPR to make the result not an lvalue. Leave such NOP_EXPRs, since RHS is being used in non-lvalue context. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 92e9e34ae07..c51d2dd912e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-08 Paolo Carlini + + PR c++/83806 + * g++.dg/warn/Wunused-parm-11.C: New. + 2018-02-08 Marek Polacek PR tree-optimization/84238 diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-11.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-11.C new file mode 100644 index 00000000000..35896df93bb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-11.C @@ -0,0 +1,13 @@ +// PR c++/83806 +// { dg-do compile { target c++11 } } +// { dg-options "-Wunused-but-set-parameter" } + +template +bool equals(X x, Y y) { + return (x == y); +} + +int main() { + const char* p = nullptr; + equals(p, nullptr); +} -- 2.30.2