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 #18

Closed
Gottox opened this issue Apr 4, 2024 · 1 comment
Closed

opaque types and ASSERT_EQ #18

Gottox opened this issue Apr 4, 2024 · 1 comment

Comments

@Gottox
Copy link

Gottox commented Apr 4, 2024

Thanks a lot for this library! I have found it quite helpful!

Nonetheless, 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);
      |         ^~~~~~~~~
@Gottox
Copy link
Author

Gottox commented Apr 4, 2024

Out of curiousity: why is typeof(x + 0) instead of typeof(x) used here?

@Gottox Gottox closed this as not planned Won't fix, can't repro, duplicate, stale Apr 7, 2024
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

No branches or pull requests

1 participant