[libcxx-commits] [libcxx] a3529aa - [libc++][test] Avoid preprocessor directives in macro argument lists (#73440)

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 27 17:38:02 PST 2023


Author: Stephan T. Lavavej
Date: 2023-11-27T17:37:59-08:00
New Revision: a3529aa92ee48552946066330f5302281a49e447

URL: https://github.com/llvm/llvm-project/commit/a3529aa92ee48552946066330f5302281a49e447
DIFF: https://github.com/llvm/llvm-project/commit/a3529aa92ee48552946066330f5302281a49e447.diff

LOG: [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.

Added: 
    

Modified: 
    libcxx/test/std/input.output/iostream.format/print.fun/print.file.pass.cpp
    libcxx/test/std/input.output/iostream.format/print.fun/println.file.pass.cpp
    libcxx/test/std/input.output/iostream.format/print.fun/vprint_nonunicode.file.pass.cpp
    libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.file.pass.cpp
    libcxx/test/support/test_macros.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/input.output/iostream.format/print.fun/print.file.pass.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/print.file.pass.cpp
index 4a397d3e3d6328f..3edc0e2245d649e 100644
--- a/libcxx/test/std/input.output/iostream.format/print.fun/print.file.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/print.file.pass.cpp
@@ -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'));

diff  --git a/libcxx/test/std/input.output/iostream.format/print.fun/println.file.pass.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/println.file.pass.cpp
index ebdddd074faf51c..07272ebb57e5fc1 100644
--- a/libcxx/test/std/input.output/iostream.format/print.fun/println.file.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/println.file.pass.cpp
@@ -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'));

diff  --git a/libcxx/test/std/input.output/iostream.format/print.fun/vprint_nonunicode.file.pass.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/vprint_nonunicode.file.pass.cpp
index 9eb85f3b7b2d874..edc8bb3f543c466 100644
--- a/libcxx/test/std/input.output/iostream.format/print.fun/vprint_nonunicode.file.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/vprint_nonunicode.file.pass.cpp
@@ -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'));

diff  --git a/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.file.pass.cpp b/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.file.pass.cpp
index 28379b9db50ed58..bd9b99166922ff0 100644
--- a/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.file.pass.cpp
+++ b/libcxx/test/std/input.output/iostream.format/print.fun/vprint_unicode.file.pass.cpp
@@ -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'));

diff  --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h
index e549ec2ca7a1a71..f3c6d8080ff6d83 100644
--- a/libcxx/test/support/test_macros.h
+++ b/libcxx/test/support/test_macros.h
@@ -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


        


More information about the libcxx-commits mailing list