C loss of data or precision is not warned about by compiler

2

Apple's LLVM does not warn about this problem, even when -Wall is specified:

uint8_t tta;
typedef uint32_t TT;
TT ttb;
ttb= 0xdeadbeef;
tta = ttb;
// here tta is only 0xEF

What can be done to force the compiler to warn about loss of data during assignment?

c
macos
clang
llvm
compiler-warnings
asked on Stack Overflow Sep 12, 2017 by fff444 • edited Sep 12, 2017 by Paul R

1 Answer

2

If you use -Wconversion you get a warning:

<stdin>:9:7: warning: implicit conversion loses integer precision: 'TT' (aka 'unsigned int') to 'uint8_t' (aka 'unsigned char') [-Wconversion]
tta = ttb;
    ~ ^~~
1 warning generated.

This was generated by the current release version of Apple's developer tools:

Apple LLVM version 8.1.0 (clang-802.0.42)

answered on Stack Overflow Sep 12, 2017 by Paul R • edited Sep 12, 2017 by Paul R

User contributions licensed under CC BY-SA 3.0