+2020-05-06 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94938
+ * pt.c (tsubst_copy_and_build): Call type_dependent_expression_p_push
+ instead of uses_template_parms. Move the warning_sentinels after the
+ RECURs.
+
2020-05-06 Jakub Jelinek <jakub@redhat.com>
PR c++/94951
{
/* If T was type-dependent, suppress warnings that depend on the range
of the types involved. */
- bool was_dep = uses_template_parms (t);
+ bool was_dep = type_dependent_expression_p_push (t);
+
+ tree op0 = RECUR (TREE_OPERAND (t, 0));
+ tree op1 = RECUR (TREE_OPERAND (t, 1));
+
warning_sentinel s1(warn_type_limits, was_dep);
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);
- tree op0 = RECUR (TREE_OPERAND (t, 0));
- tree op1 = RECUR (TREE_OPERAND (t, 1));
tree r = build_x_binary_op
(input_location, TREE_CODE (t),
op0,
+2020-05-06 Marek Polacek <polacek@redhat.com>
+
+ PR c++/94938
+ * g++.dg/warn/Wdiv-by-zero-3.C: New test.
+ * g++.dg/warn/Wtype-limits4.C: New test.
+ * g++.dg/warn/template-2.C: New test.
+ * g++.old-deja/g++.pt/crash10.C: Add dg-warning.
+
2020-05-06 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/94970
--- /dev/null
+// PR c++/94938
+
+template <typename T, int N> int
+foo (T t, int i)
+{
+ int m1 = 10 / t;
+ int m2 = 10 / i;
+ int m3 = 10 / (sizeof(T) - sizeof(int)); // { dg-warning "division by" }
+ int m4 = 10 / N; // { dg-warning "division by" }
+ return m1 + m2 + m3 + m4;
+}
+
+void
+f ()
+{
+ foo<int, 0>(0, 0);
+}
--- /dev/null
+// PR c++/94938
+// { dg-additional-options "-Wtype-limits" }
+
+template<unsigned N> struct B { unsigned arr[N]; };
+template<> struct B<1u> { int arr[10]; };
+
+template <unsigned N> bool
+foo(B<N> l)
+{
+ int i = 0;
+ return l.arr[i] < 0;
+}
+
+void
+j()
+{
+ B<1u> b;
+ foo (b);
+ B<2u> b2;
+ // I think that in this instantiation we could warn, but it breaks
+ // gcc bootstrap (marek 5/2020).
+ foo (b2);
+}
--- /dev/null
+// PR c++/94938 - ICE in value_dependent_expression_p in C++98 mode.
+// { dg-do compile }
+
+template <typename> struct S { S(); S(bool); };
+
+struct C {
+ bool operator()(S<float>);
+};
+
+S<float> fn (bool);
+
+template<typename T> void
+foo (T)
+{
+ S<float> s;
+ S<float> x = fn(false || C()(s));
+}
+
+int main ()
+{
+ foo(int());
+}
enum { val = (N == 0) ? M : GCD<N, M % N>::val };
// { dg-error "constant expression" "valid" { target *-*-* } .-1 }
// { dg-message "template argument" "valid" { target *-*-* } .-2 }
+// { dg-warning "division by" "" { target *-*-* } .-3 }
};
int main() {