PR c++/44648 - missing -Wunused warning on a const variable in if statement
authorMartin Sebor <msebor@redhat.com>
Sun, 3 Feb 2019 21:48:27 +0000 (21:48 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Sun, 3 Feb 2019 21:48:27 +0000 (14:48 -0700)
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wunused-var-35.C: New test.

From-SVN: r268503

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-var-35.C [new file with mode: 0644]

index 30ac08b77abbeba28ed99f91a0429a92bf259a55..3bcef91f752fc86836d996b9d45ca0b2e9a8b4aa 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-03  Martin Sebor  <msebor@redhat.com>
+
+       PR c++/44648
+       * g++.dg/warn/Wunused-var-35.C: New test.
+
 2019-02-03  Richard Biener  <rguenther@suse.de>
 
        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 (file)
index 0000000..6e1308c
--- /dev/null
@@ -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;
+}
+