Skip to content

Commit

Permalink
[libc++][test] Avoid preprocessor directives in macro argument lists (#…
Browse files Browse the repository at this point in the history
…73440)

Found while running libc++'s test suite with MSVC's STL.

MSVC has a level 1 "warning C5101: use of preprocessor directive in
function-like macro argument list is undefined behavior". I don't know
why Clang doesn't complain about this.

There are some formatting tests which densely interleave preprocessor
directives within function-like macros, and they would need invasive
changes. For now, I'm just skipping those tests.

However, a few tests were only slightly affected, and I was able to add
a new test macro `TEST_IF_AIX` to make them portable.
  • Loading branch information
StephanTLavavej authored Nov 28, 2023
1 parent 8b3944c commit a3529aa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ static void test_read_only() {
TEST_VALIDATE_EXCEPTION(
std::system_error,
[&]([[maybe_unused]] const std::system_error& e) {
#ifdef _AIX
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
#else
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
#endif
[[maybe_unused]] std::string_view what{
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
TEST_LIBCPP_REQUIRE(
e.what() == what,
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,8 @@ static void test_read_only() {
TEST_VALIDATE_EXCEPTION(
std::system_error,
[&]([[maybe_unused]] const std::system_error& e) {
#ifdef _AIX
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
#else
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
#endif
[[maybe_unused]] std::string_view what{
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
TEST_LIBCPP_REQUIRE(
e.what() == what,
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ static void test_read_only() {
TEST_VALIDATE_EXCEPTION(
std::system_error,
[&]([[maybe_unused]] const std::system_error& e) {
#ifdef _AIX
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
#else
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
#endif
[[maybe_unused]] std::string_view what{
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
TEST_LIBCPP_REQUIRE(
e.what() == what,
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,8 @@ static void test_read_only() {
TEST_VALIDATE_EXCEPTION(
std::system_error,
[&]([[maybe_unused]] const std::system_error& e) {
#ifdef _AIX
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
#else
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
#endif
[[maybe_unused]] std::string_view what{
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
TEST_LIBCPP_REQUIRE(
e.what() == what,
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
Expand Down
6 changes: 6 additions & 0 deletions libcxx/test/support/test_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,10 @@ inline void DoNotOptimize(Tp const& value) {
# define TEST_WORKAROUND_BUG_109234844_WEAK /* nothing */
#endif

#ifdef _AIX
# define TEST_IF_AIX(arg_true, arg_false) arg_true
#else
# define TEST_IF_AIX(arg_true, arg_false) arg_false
#endif

#endif // SUPPORT_TEST_MACROS_HPP

0 comments on commit a3529aa

Please sign in to comment.