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

Fix a null compare against an opaque struct. #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,14 @@ UTEST(c, Near) {
}

UTEST(c, Todo) { UTEST_SKIP("Not yet implemented!"); }

// TODO: TCC cannot handle comparing null opaque structs at all.
#if !defined(__TINYC__)
struct Opaque;

UTEST(c, Opaque) {
struct Opaque *opaque = NULL;
EXPECT_EQ(NULL, opaque);
ASSERT_EQ(NULL, opaque);
}
#endif
11 changes: 11 additions & 0 deletions test/test11.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,14 @@ UTEST(c11, Near) {
}

UTEST(c11, Todo) { UTEST_SKIP("Not yet implemented!"); }

// TODO: TCC cannot handle comparing null opaque structs at all.
#if !defined(__TINYC__)
struct Opaque;

UTEST(c11, Opaque) {
struct Opaque *opaque = NULL;
EXPECT_EQ(NULL, opaque);
ASSERT_EQ(NULL, opaque);
}
#endif
17 changes: 17 additions & 0 deletions test/test11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,20 @@ UTEST(cpp11, Null) {
}

#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

struct Opaque;

UTEST(cpp11, Opaque) {
struct Opaque *opaque = nullptr;
EXPECT_EQ(nullptr, opaque);
ASSERT_EQ(nullptr, opaque);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
17 changes: 17 additions & 0 deletions test/test14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,20 @@ UTEST(cpp14, Null) {
}

#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

struct Opaque;

UTEST(cpp14, Opaque) {
struct Opaque *opaque = nullptr;
EXPECT_EQ(nullptr, opaque);
ASSERT_EQ(nullptr, opaque);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
17 changes: 17 additions & 0 deletions test/test17.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,20 @@ UTEST(cpp17, Null) {
}

#endif

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
#endif

struct Opaque;

UTEST(cpp17, Opaque) {
struct Opaque *opaque = nullptr;
EXPECT_EQ(nullptr, opaque);
ASSERT_EQ(nullptr, opaque);
}

#ifdef __clang__
#pragma clang diagnostic pop
#endif
11 changes: 11 additions & 0 deletions test/test99.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,14 @@ UTEST(c99, Near) {
}

UTEST(c99, Todo) { UTEST_SKIP("Not yet implemented!"); }

// TODO: TCC cannot handle comparing null opaque structs at all.
#if !defined(__TINYC__)
struct Opaque;

UTEST(c99, Opaque) {
struct Opaque *opaque = NULL;
EXPECT_EQ(NULL, opaque);
ASSERT_EQ(NULL, opaque);
}
#endif
17 changes: 6 additions & 11 deletions utest.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,9 @@ utest_type_printer(long long unsigned int i) {
: "%llu", float \
: "%f", double \
: "%f", long double \
: "%Lf", default \
: _Generic((val - val), ptrdiff_t \
: "%p", default \
: "undef")), \
: "%Lf", void * \
: "%p", default \
: "undef"), \
(val))
#else
/*
Expand All @@ -674,24 +673,20 @@ utest_type_printer(long long unsigned int i) {

#if defined(__cplusplus) && (__cplusplus >= 201103L)
#define UTEST_AUTO(x) auto
#elif !defined(__cplusplus)

#if defined(__clang__)
#elif defined(__clang__)
/* clang-format off */
/* had to disable clang-format here because it malforms the pragmas */
#define UTEST_AUTO(x) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wgnu-auto-type\"") __auto_type \
_Pragma("clang diagnostic pop")
/* clang-format on */
#elif !defined(__clang__) && defined(__GNUC__) && !defined(__cplusplus)
#define UTEST_AUTO(x) __auto_type
#else
#define UTEST_AUTO(x) __typeof__(x + 0)
#endif

#else
#define UTEST_AUTO(x) typeof(x + 0)
#endif

#if defined(__clang__)
#define UTEST_STRNCMP(x, y, size) \
_Pragma("clang diagnostic push") \
Expand Down
Loading