diff options
author | Jason Merrill <jason@redhat.com> | 2022-06-22 23:50:23 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-06-23 11:06:25 -0400 |
commit | 6e4d5300c1f62c3f0cd1bf859b0ee6bb4e31e434 (patch) | |
tree | eb39ee5a314c4cca8635295202c1feedc0a244ca | |
parent | 8a15cd3396aa08dc2633982481fe392af0aa9e78 (diff) | |
download | gcc-6e4d5300c1f62c3f0cd1bf859b0ee6bb4e31e434.zip gcc-6e4d5300c1f62c3f0cd1bf859b0ee6bb4e31e434.tar.gz gcc-6e4d5300c1f62c3f0cd1bf859b0ee6bb4e31e434.tar.bz2 |
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.cc | 1 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/constexpr-if37.C | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 80d2bec..4535c14 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -20438,6 +20438,7 @@ tsubst_copy_and_build (tree t, warning_sentinel s2(warn_div_by_zero, was_dep); warning_sentinel s3(warn_logical_op, was_dep); warning_sentinel s4(warn_tautological_compare, was_dep); + warning_sentinel s5(warn_address, was_dep); tree r = build_x_binary_op (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 0000000..e11e02c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if37.C @@ -0,0 +1,21 @@ +// PR c++/105885 +// { dg-do compile { target c++17 } } +// { dg-additional-options -Wall } + +int i; + +template<const char* ARG = nullptr> +void test() { + if constexpr(ARG == nullptr) { + ++i; + } else { + --i; + } +} + +const char CONSTSTR[] = {'\n', '\t', ' ', '\0'}; + +int main() { + test(); + test<CONSTSTR>(); +} |