utest.h
utest.h copied to clipboard
Use __auto_type for GCC. __typeof__(x + 0) expr eval to different type then x.
Hi,
Adding "+ 0" results in type change (implicit type conversion caused by arithmetic operation). Testcase:
#include "utest.h"
UTEST(type_eval, plus_int_zero)
{
uint8_t a = 1;
size_t b = 1;
EXPECT_EQ(a, b);
}
UTEST_MAIN()
gcc problem.c -Wall -Wextra -pedantic
In file included from problem.c:1:
problem.c: In function ‘utest_run_type_eval_plus_int_zero’:
utest.h:826:42: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
826 | #define EXPECT_EQ(x, y) UTEST_COND(x, y, ==, "", 0)
| ^~
utest.h:783:18: note: in definition of macro ‘UTEST_COND’
783 | if (!((xEval)cond(yEval))) { \
| ^~~~
problem.c:8:5: note: in expansion of macro ‘EXPECT_EQ’
8 | EXPECT_EQ(a, b);
|
Not sure why originally __auto_type was used only for CLANG (as I understand its GNU GCC ext. https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Auto-Type.html)
Honesty? I don't use GCC on any platform anymore, so didn't know. Lets see it if passes CI! Happy to land though, PR looks good.