mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
Catch and warn demotion of double in assignments
This commit is contained in:
parent
08ca59d0df
commit
c5ce18591f
4 changed files with 25 additions and 1 deletions
|
@ -151,6 +151,10 @@ check_types_compatible (expr_t *dst, expr_t *src)
|
|||
|
||||
if (type_assignable (dst_type, src_type)) {
|
||||
if (is_scalar (dst_type) && is_scalar (src_type)) {
|
||||
if (is_double (src_type)) {
|
||||
warning (dst, "assignment of double to %s (use a cast)\n",
|
||||
dst_type->name);
|
||||
}
|
||||
// the types are different but cast-compatible
|
||||
expr_t *new = cast_expr (dst_type, src);
|
||||
// the cast was a no-op, so the types are compatible at the
|
||||
|
|
|
@ -61,8 +61,10 @@ test_progs_dat=\
|
|||
fail_progs_dat=
|
||||
|
||||
test_build_errors=\
|
||||
double-demote-int.r \
|
||||
double-demote-float.r \
|
||||
double-demote-float-linit.r \
|
||||
double-demote-int.r \
|
||||
double-demote-int-linit.r \
|
||||
double-int-compare.r \
|
||||
double-float-compare.r
|
||||
|
||||
|
@ -161,6 +163,12 @@ double-demote-int.run$(EXEEXT): double-demote-int.r Makefile build-compile-fail-
|
|||
double-demote-float.run$(EXEEXT): double-demote-float.r Makefile build-compile-fail-run
|
||||
$(srcdir)/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $<
|
||||
|
||||
double-demote-int-linit.run$(EXEEXT): double-demote-int-linit.r Makefile build-compile-fail-run
|
||||
$(srcdir)/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $<
|
||||
|
||||
double-demote-float-linit.run$(EXEEXT): double-demote-float-linit.r Makefile build-compile-fail-run
|
||||
$(srcdir)/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $<
|
||||
|
||||
double-int-compare.run$(EXEEXT): double-int-compare.r Makefile build-compile-fail-run
|
||||
$(srcdir)/build-compile-fail-run $@ $(QFCC) $(QCFLAGS) $<
|
||||
|
||||
|
|
6
tools/qfcc/test/double-demote-float-linit.r
Normal file
6
tools/qfcc/test/double-demote-float-linit.r
Normal file
|
@ -0,0 +1,6 @@
|
|||
double a;
|
||||
int main ()
|
||||
{
|
||||
float b = a;
|
||||
return 1; // test fails if compile succeeds
|
||||
}
|
6
tools/qfcc/test/double-demote-int-linit.r
Normal file
6
tools/qfcc/test/double-demote-int-linit.r
Normal file
|
@ -0,0 +1,6 @@
|
|||
double a;
|
||||
int main ()
|
||||
{
|
||||
int b = a;
|
||||
return 1; // test fails if compile succeeds
|
||||
}
|
Loading…
Reference in a new issue