diff options
author | Marek Polacek <polacek@redhat.com> | 2019-08-28 02:22:29 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-08-28 02:22:29 +0000 |
commit | 8692693732e89806058d3b9c91132fb83661b214 (patch) | |
tree | 4d6fb359b2dfa84fd95432293af3448db1c32dd2 /gcc/testsuite | |
parent | 14da3939da3adcef84816573caa9d93c7367507e (diff) | |
download | gcc-8692693732e89806058d3b9c91132fb83661b214.zip gcc-8692693732e89806058d3b9c91132fb83661b214.tar.gz gcc-8692693732e89806058d3b9c91132fb83661b214.tar.bz2 |
PR c++/81676 - bogus -Wunused warnings in constexpr if.
* semantics.c (maybe_mark_exp_read_r): New function.
(finish_if_stmt): Call it on THEN_CLAUSE and ELSE_CLAUSE.
* g++.dg/cpp1z/constexpr-if31.C: New test.
* g++.dg/cpp1z/constexpr-if32.C: New test.
From-SVN: r274982
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/constexpr-if31.C | 79 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/constexpr-if32.C | 16 |
3 files changed, 99 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ade1a69..4c58780 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2019-08-27 Marek Polacek <polacek@redhat.com> + PR c++/81676 - bogus -Wunused warnings in constexpr if. + * g++.dg/cpp1z/constexpr-if31.C: New test. + * g++.dg/cpp1z/constexpr-if32.C: New test. + PR c++/91428 - warn about std::is_constant_evaluated in if constexpr. * g++.dg/cpp2a/is-constant-evaluated9.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if31.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if31.C new file mode 100644 index 0000000..02140cf --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if31.C @@ -0,0 +1,79 @@ +// PR c++/81676 - bogus -Wunused warnings in constexpr if. +// { dg-do compile { target c++17 } } +// { dg-options "-Wall -Wextra" } + +template <typename T> int +f1 (T v) +{ + T x = 0; + if constexpr(sizeof(T) == sizeof(int)) + return v + x; + else + return 0; +} + +template <typename T> int +f2 (T v) // { dg-warning "unused parameter .v." } +{ + T x = 0; + if constexpr(sizeof(T) == sizeof(int)) + return x; + else + return 0; +} + +template <typename T> int +f3 (T v) +{ + T x = 0; // { dg-warning "unused variable .x." } + if constexpr(sizeof(T) == sizeof(int)) + return v; + else + return 0; +} + +template <typename T> int +f4 (T v) +{ + T x = 0; + if constexpr(sizeof(T) == sizeof(int)) + return 0; + else + return v + x; +} + +template <typename T> int +f5 (T v) // { dg-warning "unused parameter .v." } +{ + T x = 0; + if constexpr(sizeof(T) == sizeof(int)) + return 0; + else + return x; +} + +template <typename T> int +f6 (T v) +{ + T x = 0; // { dg-warning "unused variable .x." } + if constexpr(sizeof(T) == sizeof(int)) + return 0; + else + return v; +} + +int main() +{ + f1(0); + f1('a'); + f2(0); + f2('a'); + f3(0); + f3('a'); + f4(0); + f4('a'); + f5(0); + f5('a'); + f6(0); + f6('a'); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if32.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if32.C new file mode 100644 index 0000000..13a6039 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if32.C @@ -0,0 +1,16 @@ +// PR c++/81676 - bogus -Wunused warnings in constexpr if. +// { dg-do compile { target c++17 } } +// { dg-options "-Wall -Wextra" } + +int main() +{ + auto f = [](auto a, auto b) { + if constexpr (sizeof(b) == 1) { + return a; + } else { + return b; + } + }; + + return f(1, 1) + f(1, 'a'); +} |