From 0b841214a8c8a56d4c4d391fddf780faba3f5748 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Sun, 3 Feb 2019 21:48:27 +0000 Subject: [PATCH] PR c++/44648 - missing -Wunused warning on a const variable in if statement gcc/testsuite/ChangeLog: * g++.dg/warn/Wunused-var-35.C: New test. From-SVN: r268503 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Wunused-var-35.C | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-35.C diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 30ac08b77ab..3bcef91f752 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-02-03 Martin Sebor + + PR c++/44648 + * g++.dg/warn/Wunused-var-35.C: New test. + 2019-02-03 Richard Biener PR debug/87295 diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-35.C b/gcc/testsuite/g++.dg/warn/Wunused-var-35.C new file mode 100644 index 00000000000..6e1308c8e03 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-35.C @@ -0,0 +1,19 @@ +// PR c++/44648 - missing -Wunused warning on a const variable in if statement +// { dg-do compile } +// { dg-options "-Wunused" } + +int main() +{ + bool b0 = 1; // { dg-warning "\\\[-Wunused-variable\\\]" } + const bool b00 = 1; // { dg-warning "\\\[-Wunused-variable\\\]" } + if (bool b1 = 1) // { dg-warning "\\\[-Wunused-variable\\\]" } + return 0; + else + return 1; + + if (const bool b2 = 1) // { dg-warning "\\\[-Wunused-variable\\\]" "bug" { xfail c++98_only } } + return 0; + else + return 1; +} + -- 2.30.2