Skip to content

Commit 1365dbe

Browse files
committed
Improve ASSERT_LOWERCASE behavior for standard library headers leaking C assert. Libc++ does this.
1 parent 2fa0467 commit 1365dbe

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

include/assert.hpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,15 +1364,10 @@ using libassert::ASSERTION;
13641364
#endif
13651365

13661366
#ifdef ASSERT_LOWERCASE
1367-
#ifdef assert
1368-
#undef assert
1369-
#endif
13701367
#ifndef NDEBUG
13711368
#define debug_assert(expr, ...) ASSERT_INVOKE(expr, false, true, "debug_assert", debug_assertion, , __VA_ARGS__)
1372-
#define assert(expr, ...) ASSERT_INVOKE(expr, true, true, "assert", assertion, , __VA_ARGS__)
13731369
#else
13741370
#define debug_assert(expr, ...) (void)0
1375-
#define assert(expr, ...) ASSERT_INVOKE(expr, true, false, "assert", assertion, , __VA_ARGS__)
13761371
#endif
13771372
#endif
13781373

@@ -1407,3 +1402,16 @@ using libassert::ASSERTION;
14071402
#endif
14081403

14091404
#endif
1405+
1406+
// Intentionally done outside the include guard. Libc++ leaks `assert` (among other things), so the include for
1407+
// assert.hpp should go after other includes when using -DASSERT_LOWERCASE.
1408+
#ifdef ASSERT_LOWERCASE
1409+
#ifdef assert
1410+
#undef assert
1411+
#endif
1412+
#ifndef NDEBUG
1413+
#define assert(expr, ...) ASSERT_INVOKE(expr, true, true, "assert", assertion, , __VA_ARGS__)
1414+
#else
1415+
#define assert(expr, ...) ASSERT_INVOKE(expr, true, false, "assert", assertion, , __VA_ARGS__)
1416+
#endif
1417+
#endif

0 commit comments

Comments
 (0)