aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/typeck.cc3
-rw-r--r--gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C26
2 files changed, 28 insertions, 1 deletions
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 4605f73..2e0fd8f 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -6179,7 +6179,8 @@ cp_build_binary_op (const op_location_t &location,
}
if (may_need_excess_precision
&& (orig_type0 != type0 || orig_type1 != type1)
- && build_type == NULL_TREE)
+ && build_type == NULL_TREE
+ && result_type)
{
gcc_assert (common);
semantic_result_type = cp_common_type (orig_type0, orig_type1);
diff --git a/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C
new file mode 100644
index 0000000..627e8a5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops2.C
@@ -0,0 +1,26 @@
+// PR c++/107382
+// PR c++/107383
+// { dg-do compile }
+// { dg-options "-O2 -fexcess-precision=standard" }
+
+void
+foo ()
+{
+ float t[2] = { 1, 2 };
+ int const *s = 0;
+ t[1] / s; // { dg-error "invalid operands of types 'float' and 'const int\\\*' to binary 'operator/'" }
+}
+
+void
+bar ()
+{
+ float t[2] = { 1, 2 };
+ int const *s[2] = { 0, 0 };
+ t[1] / s[0]; // { dg-error "invalid operands of types 'float' and 'const int\\\*' to binary 'operator/'" }
+}
+
+void
+baz (float a, int* b)
+{
+ a -= b; // { dg-error "invalid operands of types 'float' and 'int\\\*' to binary 'operator-'" }
+}