From 556f8de3bec99dfe1dac15fecc704025d22b8fd4 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Sun, 1 Sep 2019 22:54:15 +0000 Subject: [PATCH] PR c++/91129 - wrong error with binary op in template argument. * typeck.c (warn_for_null_address): Use fold_for_warn instead of fold_non_dependent_expr. (cp_build_binary_op): Likewise. * g++.dg/cpp1y/nontype1.C: New test. From-SVN: r275285 --- gcc/cp/ChangeLog | 7 ++++++ gcc/cp/typeck.c | 18 ++++++--------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp1y/nontype1.C | 42 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/nontype1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9725dda..8eb81c5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-09-01 Marek Polacek + + PR c++/91129 - wrong error with binary op in template argument. + * typeck.c (warn_for_null_address): Use fold_for_warn instead of + fold_non_dependent_expr. + (cp_build_binary_op): Likewise. + 2019-08-30 Jason Merrill Add source location to TRAIT_EXPR. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index d4f2d98..70094d1 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4305,7 +4305,7 @@ warn_for_null_address (location_t location, tree op, tsubst_flags_t complain) || TREE_NO_WARNING (op)) return; - tree cop = fold_non_dependent_expr (op, complain); + tree cop = fold_for_warn (op); if (TREE_CODE (cop) == ADDR_EXPR && decl_with_nonnull_addr_p (TREE_OPERAND (cop, 0)) @@ -4628,9 +4628,8 @@ cp_build_binary_op (const op_location_t &location, || code1 == COMPLEX_TYPE || code1 == VECTOR_TYPE)) { enum tree_code tcode0 = code0, tcode1 = code1; - tree cop1 = fold_non_dependent_expr (op1, complain); doing_div_or_mod = true; - warn_for_div_by_zero (location, cop1); + warn_for_div_by_zero (location, fold_for_warn (op1)); if (tcode0 == COMPLEX_TYPE || tcode0 == VECTOR_TYPE) tcode0 = TREE_CODE (TREE_TYPE (TREE_TYPE (op0))); @@ -4669,11 +4668,8 @@ cp_build_binary_op (const op_location_t &location, case TRUNC_MOD_EXPR: case FLOOR_MOD_EXPR: - { - tree cop1 = fold_non_dependent_expr (op1, complain); - doing_div_or_mod = true; - warn_for_div_by_zero (location, cop1); - } + doing_div_or_mod = true; + warn_for_div_by_zero (location, fold_for_warn (op1)); if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE && TREE_CODE (TREE_TYPE (type0)) == INTEGER_TYPE @@ -4766,7 +4762,7 @@ cp_build_binary_op (const op_location_t &location, } else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) { - tree const_op1 = fold_non_dependent_expr (op1, complain); + tree const_op1 = fold_for_warn (op1); if (TREE_CODE (const_op1) != INTEGER_CST) const_op1 = op1; result_type = type0; @@ -4812,10 +4808,10 @@ cp_build_binary_op (const op_location_t &location, } else if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE) { - tree const_op0 = fold_non_dependent_expr (op0, complain); + tree const_op0 = fold_for_warn (op0); if (TREE_CODE (const_op0) != INTEGER_CST) const_op0 = op0; - tree const_op1 = fold_non_dependent_expr (op1, complain); + tree const_op1 = fold_for_warn (op1); if (TREE_CODE (const_op1) != INTEGER_CST) const_op1 = op1; result_type = type0; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0761ba1..862e55d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-01 Marek Polacek + + PR c++/91129 - wrong error with binary op in template argument. + * g++.dg/cpp1y/nontype1.C: New test. + 2019-09-01 Iain Sandoe * gcc.c-torture/compile/20190827-1.c: Add dg-requires-alias. diff --git a/gcc/testsuite/g++.dg/cpp1y/nontype1.C b/gcc/testsuite/g++.dg/cpp1y/nontype1.C new file mode 100644 index 0000000..a37e996 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/nontype1.C @@ -0,0 +1,42 @@ +// PR c++/91129 - wrong error with binary op in template argument. +// { dg-do compile { target c++14 } } + +template +struct C +{ + constexpr operator T() const { return v; } + constexpr auto operator()() const { return v; } +}; + +template +struct A +{ +}; + +template +void foo () +{ + A{}> a0; + A{}> a1; + A{}> a2; + A{}> a3; + A{}> a4; + A{}> a5; + A{}> a6; + A{}> a7; + A{}> a8; + A{}> a9; + A{}> a10; + A> C{})> a11; + A{}> a12; + A{}> a13; + A{}> a14; + A{}> a15; + A{}> a16; + A{}> a17; +} + +int main() +{ + foo<10>(); +} -- 2.7.4