[libcxx-commits] [PATCH] D100029: [libcxx][test] Properly construct containers in debug mode tests for map/set

Marek Kurdej via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 9 00:38:12 PDT 2021


curdeius added inline comments.


================
Comment at: libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_7.pass.cpp:16
 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DEBUG=1
 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
 
----------------
To answer @Quuxplusone's point 2), you can do just something like the suggested edits here... (see another comment for the rest)

Comparing the assertion messages may be a bit difficult though, and brittle.

I.e. if we wanted to do something like:
```
#include <assert.h>
#include <stdlib.h>
#include <string.h>

void test_assertion(const char* msg) {
    assert(::strcmp(msg, "expected") == 0);
    ::exit(::test_exit_code);
}

#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : ::test_assertion(m))
```

we hit the problem that we include some headers for assert, exit and strcmp, but we redefine `_LIBCPP_ASSERT` afterwards.
Also these headers might get included transitively by later includes (but won't be because of header guards), but they'll have `_LIBCPP_ASSERT` not redefined.

An orthogonal problem is to have the actual message when `assert(strcmp(...)...);` fails.


================
Comment at: libcxx/test/libcxx/containers/unord/unord.map/db_local_iterators_7.pass.cpp:34
+    assert(i == c.end(b));
     ++i;
     assert(false);
----------------
... and then here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100029/new/

https://reviews.llvm.org/D100029



More information about the libcxx-commits mailing list