summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-06-22 23:50:23 -0400
committerJason Merrill <jason@redhat.com>2022-06-23 11:45:27 -0400
commitb96b64bec37c3dddf1f0f93c27ceb4fd5685c70a (patch)
tree76db0644a37daa6cec96e14cff12729f5308f575
parentipa-icf: skip variables with body_removed (diff)
downloadgcc-b96b64bec37c3dddf1f0f93c27ceb4fd5685c70a.tar.gz
gcc-b96b64bec37c3dddf1f0f93c27ceb4fd5685c70a.tar.bz2
gcc-b96b64bec37c3dddf1f0f93c27ceb4fd5685c70a.tar.xz
c++: -Waddress and value-dependent expr [PR105885]
We already suppress various warnings for code that would be tautological if written directly, but not when it's the result of template substitution. It seems we need to do this for -Waddress as well. PR c++/105885 gcc/cp/ChangeLog: * pt.cc (tsubst_copy_and_build): Also suppress -Waddress for comparison of dependent operands. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-if37.C: New test.
-rw-r--r--gcc/cp/pt.cc1
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/constexpr-if37.C21
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 67238000109..e8bf1692c74 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -20364,6 +20364,7 @@ tsubst_copy_and_build (tree t,
20364 warning_sentinel s2(warn_div_by_zero, was_dep); 20364 warning_sentinel s2(warn_div_by_zero, was_dep);
20365 warning_sentinel s3(warn_logical_op, was_dep); 20365 warning_sentinel s3(warn_logical_op, was_dep);
20366 warning_sentinel s4(warn_tautological_compare, was_dep); 20366 warning_sentinel s4(warn_tautological_compare, was_dep);
20367 warning_sentinel s5(warn_address, was_dep);
20367 20368
20368 tree r = build_x_binary_op 20369 tree r = build_x_binary_op
20369 (input_location, TREE_CODE (t), 20370 (input_location, TREE_CODE (t),
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if37.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if37.C
new file mode 100644
index 00000000000..e11e02cfa0e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if37.C
@@ -0,0 +1,21 @@
1// PR c++/105885
2// { dg-do compile { target c++17 } }
3// { dg-additional-options -Wall }
4
5int i;
6
7template<const char* ARG = nullptr>
8void test() {
9 if constexpr(ARG == nullptr) {
10 ++i;
11 } else {
12 --i;
13 }
14}
15
16const char CONSTSTR[] = {'\n', '\t', ' ', '\0'};
17
18int main() {
19 test();
20 test<CONSTSTR>();
21}