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

opaque types and ASSERT_EQ #153

Open
Gottox opened this issue Apr 7, 2024 · 1 comment · May be fixed by #155
Open

opaque types and ASSERT_EQ #153

Gottox opened this issue Apr 7, 2024 · 1 comment · May be fixed by #155

Comments

@Gottox
Copy link
Contributor

Gottox commented Apr 7, 2024

I'm facing the issue, that I have problems when I do NULL checks for opaque types:

#include "utest.h"

struct Foo;

UTEST(a, b) {
	struct Foo *foo = NULL;
	ASSERT_EQ(NULL, foo);
}

UTEST_MAIN();

clang-17 works here, but if I compile with gcc-13 I get the following error:

In file included from t.c:1:
t.c: In function 'utest_run_a_b':
utest.h:678:36: error: invalid use of undefined type 'struct Foo'
  678 | #define UTEST_AUTO(x) __typeof__(x + 0)
      |                                    ^
utest.h:754:5: note: in expansion of macro 'UTEST_AUTO'
  754 |     UTEST_AUTO(y) yEval = (y);                                                 \
      |     ^~~~~~~~~~
utest.h:800:25: note: in expansion of macro 'UTEST_COND'
  800 | #define ASSERT_EQ(x, y) UTEST_COND(x, y, ==, "", 1)
      |                         ^~~~~~~~~~
t.c:7:9: note: in expansion of macro 'ASSERT_EQ'
    7 |         ASSERT_EQ(NULL, foo);
      |         ^~~~~~~~~
utest.h:643:41: error: arithmetic on pointer to an incomplete type
  643 |                         : _Generic((val - val), ptrdiff_t                      \
      |                                         ^
utest.h:405:33: note: in definition of macro 'UTEST_PRINTF'
  405 |     fprintf(utest_state.output, __VA_ARGS__);                                  \
      |                                 ^~~~~~~~~~~
utest.h:765:7: note: in expansion of macro 'utest_type_printer'
  765 |       utest_type_printer(yEval);                                               \
      |       ^~~~~~~~~~~~~~~~~~
utest.h:800:25: note: in expansion of macro 'UTEST_COND'
  800 | #define ASSERT_EQ(x, y) UTEST_COND(x, y, ==, "", 1)
      |                         ^~~~~~~~~~
t.c:7:9: note: in expansion of macro 'ASSERT_EQ'
    7 |         ASSERT_EQ(NULL, foo);
      |         ^~~~~~~~~
utest.h:643:41: error: arithmetic on pointer to an incomplete type
  643 |                         : _Generic((val - val), ptrdiff_t                      \
      |                                         ^
utest.h:407:10: note: in definition of macro 'UTEST_PRINTF'
  407 |   printf(__VA_ARGS__)
      |          ^~~~~~~~~~~
utest.h:765:7: note: in expansion of macro 'utest_type_printer'
  765 |       utest_type_printer(yEval);                                               \
      |       ^~~~~~~~~~~~~~~~~~
utest.h:800:25: note: in expansion of macro 'UTEST_COND'
  800 | #define ASSERT_EQ(x, y) UTEST_COND(x, y, ==, "", 1)
      |                         ^~~~~~~~~~
t.c:7:9: note: in expansion of macro 'ASSERT_EQ'
    7 |         ASSERT_EQ(NULL, foo);
      |         ^~~~~~~~~

Out of curiousity: Why is typeof(x + 0) instead of typeof(x) used here? - It looks like some compiler quirk that you wanted to workaround

@sheredom
Copy link
Owner

sheredom commented Apr 7, 2024

Ah indeed it was a quirk I had to workaround - that I've obviously paged completely out of my head and should have commented more closely. I'll try an necro my reasoning and fix this.

@sheredom sheredom linked a pull request Apr 7, 2024 that will close this issue
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 a pull request may close this issue.

2 participants