[Bug 271227] ATF_REQUIRE_EQ cannot be used with static_cast<const char *>(NULL)
- Reply: bugzilla-noreply_a_freebsd.org: "[Bug 271227] C++ ATF_REQUIRE_EQ cannot be used with static_cast<const char *>(NULL)"
- Reply: bugzilla-noreply_a_freebsd.org: "[Bug 271227] C++ ATF_REQUIRE_EQ cannot be used with static_cast<const char *>(NULL)"
- Reply: bugzilla-noreply_a_freebsd.org: "[Bug 271227] C++ ATF_REQUIRE_EQ cannot be used with static_cast<const char *>(NULL)"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 03 May 2023 14:00:41 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=271227
Bug ID: 271227
Summary: ATF_REQUIRE_EQ cannot be used with static_cast<const
char *>(NULL)
Product: Base System
Version: CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: misc
Assignee: bugs@FreeBSD.org
Reporter: emaste@freebsd.org
In contrib/atf/atf-c/macros.h we have:
#define ATF_REQUIRE_EQ(expected, actual) \
ATF_REQUIRE_MSG((expected) == (actual), "%s != %s", #expected, #actual)
#define ATF_REQUIRE_STREQ(expected, actual) \
ATF_REQUIRE_MSG(strcmp(expected, actual) == 0, "%s != %s (%s != %s)", \
#expected, #actual, expected, actual)
ATF_REQUIRE_EQ tests that the (arbitrary) arguments are equal, while
ATF_REQUIRE_STREQ compares (and prints differing) strings.
In contrast, in contrib/atf/atf-c++/macros.hpp we have only ATF_REQUIRE_EQ:
#define ATF_REQUIRE_EQ(expected, actual) \
do { \
if ((expected) != (actual)) { \
std::ostringstream atfu_ss; \
atfu_ss << "Line " << __LINE__ << ": " \
<< #expected << " != " << #actual \
<< " (" << (expected) << " != " << (actual) << ")"; \
atf::tests::tc::fail(atfu_ss.str()); \
} \
} while (false)
In lib/libnv/tests/cnv_tests.cc we have:
ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &cookie),
static_cast<const char *>(NULL));
which GCC warns will pass NULL to a fn with a nonnull arg:
In file included from
/usr/obj/tmp/cirrus-ci-build/amd64.amd64/tmp/usr/include/c++/v1/string:536:
In static member function 'static constexpr size_t
std::__1::char_traits<char>::length(const char_type*)',
inlined from 'std::__1::basic_ostream<char, _Traits>&
std::__1::operator<<(basic_ostream<char, _Traits>&, const char*) [with _Traits
= char_traits<char>]' at
/usr/obj/tmp/cirrus-ci-build/amd64.amd64/tmp/usr/include/c++/v1/ostream:902:43,
inlined from 'virtual void
{anonymous}::atfu_tc_cnvlist_free_nvlist_array::body() const' at
/tmp/cirrus-ci-build/lib/libnv/tests/cnv_tests.cc:1438:3:
/usr/obj/tmp/cirrus-ci-build/amd64.amd64/tmp/usr/include/c++/v1/__string/char_traits.h:218:30:
warning: argument 1 null where non-null expected [-Wnonnull]
218 | return __builtin_strlen(__s);
| ~~~~~~~~~~~~~~~~^~~~~
--
You are receiving this mail because:
You are the assignee for the bug.