Consider the following example:
#define FMT_HEADER_ONLY
#include <fmt/format.h>
//#undef assert
struct Test
{
void assert (bool pass, const char *test_name)
{
fmt::print("{}: {}", test_name, pass ? "PASS" : "FAIL");
}
};
int main()
{
Test test;
test.assert(true, "mumble");
return 0;
}
It fails compilation (godbolt) with:
<source>:7:50: error: macro "assert" passed 2 arguments, but takes just 1
7 | void assert (bool pass, const char *test_name)
| ^
In file included from /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/cassert:44,
from /opt/compiler-explorer/libs/fmt/trunk/include/fmt/format-inl.h:12,
from /opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:4230,
from <source>:2:
/usr/include/assert.h:92: note: macro "assert" defined here
92 | # define assert(expr) \
|
<source>:16:31: error: macro "assert" passed 2 arguments, but takes just 1
16 | test.assert(true, "mumble");
| ^
In file included from /opt/compiler-explorer/gcc-10.2.0/include/c++/10.2.0/cassert:44,
from /opt/compiler-explorer/libs/fmt/trunk/include/fmt/format-inl.h:12,
from /opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:4230,
from <source>:2:
/usr/include/assert.h:92: note: macro "assert" defined here
92 | # define assert(expr) \
|
<source>:7:10: error: variable or field 'assert' declared void
7 | void assert (bool pass, const char *test_name)
| ^~~~~~
<source>:10:5: error: expected ';' at end of member declaration
10 | }
| ^
| ;
<source>: In function 'int main()':
<source>:16:10: error: 'struct Test' has no member named 'assert'
16 | test.assert(true, "mumble");
| ^~~~~~
As a workaround we can #undef assert immediately after including format.h.
It looks like some work was done to remove the dependency on cassert in 2f9acd1, but this did not extend to the header only mode?
Is it just a matter of replacing the remaining assert() calls with FMT_ASSERT()?
Consider the following example:
It fails compilation (godbolt) with:
As a workaround we can
#undef assertimmediately after includingformat.h.It looks like some work was done to remove the dependency on cassert in 2f9acd1, but this did not extend to the header only mode?
Is it just a matter of replacing the remaining
assert()calls withFMT_ASSERT()?