Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use __auto_type for GCC. __typeof__(x + 0) expr eval to different type then x. #169

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wdl83
Copy link

@wdl83 wdl83 commented Jan 11, 2025

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)

@sheredom
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants