Skip to content

Commit a3529aa

Browse files
[libc++][test] Avoid preprocessor directives in macro argument lists (#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.
1 parent 8b3944c commit a3529aa

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

libcxx/test/std/input.output/iostream.format/print.fun/print.file.pass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ static void test_read_only() {
9494
TEST_VALIDATE_EXCEPTION(
9595
std::system_error,
9696
[&]([[maybe_unused]] const std::system_error& e) {
97-
#ifdef _AIX
98-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
99-
#else
100-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
101-
#endif
97+
[[maybe_unused]] std::string_view what{
98+
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
10299
TEST_LIBCPP_REQUIRE(
103100
e.what() == what,
104101
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));

libcxx/test/std/input.output/iostream.format/print.fun/println.file.pass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ static void test_read_only() {
9797
TEST_VALIDATE_EXCEPTION(
9898
std::system_error,
9999
[&]([[maybe_unused]] const std::system_error& e) {
100-
#ifdef _AIX
101-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
102-
#else
103-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
104-
#endif
100+
[[maybe_unused]] std::string_view what{
101+
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
105102
TEST_LIBCPP_REQUIRE(
106103
e.what() == what,
107104
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));

libcxx/test/std/input.output/iostream.format/print.fun/vprint_nonunicode.file.pass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,8 @@ static void test_read_only() {
103103
TEST_VALIDATE_EXCEPTION(
104104
std::system_error,
105105
[&]([[maybe_unused]] const std::system_error& e) {
106-
#ifdef _AIX
107-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
108-
#else
109-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
110-
#endif
106+
[[maybe_unused]] std::string_view what{
107+
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
111108
TEST_LIBCPP_REQUIRE(
112109
e.what() == what,
113110
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));

libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.file.pass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,8 @@ static void test_read_only() {
110110
TEST_VALIDATE_EXCEPTION(
111111
std::system_error,
112112
[&]([[maybe_unused]] const std::system_error& e) {
113-
#ifdef _AIX
114-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Broken pipe"};
115-
#else
116-
[[maybe_unused]] std::string_view what{"failed to write formatted output: Operation not permitted"};
117-
#endif
113+
[[maybe_unused]] std::string_view what{
114+
"failed to write formatted output: " TEST_IF_AIX("Broken pipe", "Operation not permitted")};
118115
TEST_LIBCPP_REQUIRE(
119116
e.what() == what,
120117
TEST_WRITE_CONCATENATED("\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));

libcxx/test/support/test_macros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,10 @@ inline void DoNotOptimize(Tp const& value) {
443443
# define TEST_WORKAROUND_BUG_109234844_WEAK /* nothing */
444444
#endif
445445

446+
#ifdef _AIX
447+
# define TEST_IF_AIX(arg_true, arg_false) arg_true
448+
#else
449+
# define TEST_IF_AIX(arg_true, arg_false) arg_false
450+
#endif
451+
446452
#endif // SUPPORT_TEST_MACROS_HPP

0 commit comments

Comments
 (0)