From a98b732181472edb4591059c868082e5e708a21c Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 16 Aug 2019 20:40:36 +0000 Subject: [PATCH] re PR c++/85827 (false positive for -Wunused-but-set-variable because of constexpr-if) PR c++/85827 g++.dg/cpp1z/constexpr-if29.C: New test. From-SVN: r274587 --- gcc/cp/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/cpp1z/constexpr-if29.C | 28 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if29.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 938ec486d9c..c1ffe2ed94f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-08-16 Marek Polacek + + PR c++/85827 + * g++.dg/cpp1z/constexpr-if29.C: New test. + 2019-08-15 Jason Merrill PR c++/90393 - ICE with thow in ?: diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if29.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if29.C new file mode 100644 index 00000000000..a40912a6fa5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if29.C @@ -0,0 +1,28 @@ +// PR c++/85827 +// { dg-do compile { target c++17 } } +// { dg-options "-Wunused-variable -Wunused-parameter" } + +template int f() +{ + constexpr bool _1 = N == 1; + constexpr bool _2 = N == 2; + constexpr bool _3 = N == 3; + + if constexpr (_1) { + return 5; + } else if constexpr (_2) { + return 1; + } else if constexpr (_3) { + return 7; + } +} + +int a() { + return f<1>(); +} +int b() { + return f<2>(); +} +int c() { + return f<3>(); +} -- 2.30.2