diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 4605f734e2d90901ed04faa54f61d150d5af5542..2e0fd8fbf1709c33494875323b55a62f2d646879 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 0000000000000000000000000000000000000000..627e8a573f100d324d18d4954517af288b555fc3 --- /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-'" } +}