Skip to content

[libc++] Guard the whole print.cpp file with _LIBCPP_WIN32API #71122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Nov 2, 2023

The print.cpp source file is only used when building on Windows. Avoid including anything else but <__config> in the file in the case where there's nothing to compile here at all. As a drive-by change, use _LIBCPP_WIN32API consistently instead of _WIN32.

The print.cpp source file is only used when building on Windows. Avoid
including anything else but <__config> in the file in the case where
there's nothing to compile here at all. As a drive-by change, use
_LIBCPP_WIN32API consistently instead of _WIN32.
@ldionne ldionne requested a review from a team as a code owner November 2, 2023 22:17
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 2, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 2, 2023

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

The print.cpp source file is only used when building on Windows. Avoid including anything else but <__config> in the file in the case where there's nothing to compile here at all. As a drive-by change, use _LIBCPP_WIN32API consistently instead of _WIN32.


Full diff: https://github.com/llvm/llvm-project/pull/71122.diff

1 Files Affected:

  • (modified) libcxx/src/print.cpp (+6-6)
diff --git a/libcxx/src/print.cpp b/libcxx/src/print.cpp
index a581dd37fe788ab..3692187a5954a32 100644
--- a/libcxx/src/print.cpp
+++ b/libcxx/src/print.cpp
@@ -7,10 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include <__config>
-#include <cstdlib>
-#include <print>
 
 #if defined(_LIBCPP_WIN32API)
+
+#  include <cstdlib>
+#  include <print>
+
 #  define WIN32_LEAN_AND_MEAN
 #  define NOMINMAX
 #  include <io.h>
@@ -19,11 +21,9 @@
 #  include <__system_error/system_error.h>
 
 #  include "filesystem/error.h"
-#endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#ifdef _WIN32
 _LIBCPP_EXPORTED_FROM_ABI bool __is_windows_terminal(FILE* __stream) {
   // Note the Standard does this in one call, but it's unclear whether
   // an invalid handle is allowed when calling GetConsoleMode.
@@ -52,6 +52,6 @@ __write_to_windows_console([[maybe_unused]] FILE* __stream, [[maybe_unused]] wst
 }
 #  endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
-#endif // _WIN32
-
 _LIBCPP_END_NAMESPACE_STD
+
+#endif // !_LIBCPP_WIN32API

@ldionne
Copy link
Member Author

ldionne commented Nov 2, 2023

Another option here would be to exclude the .cpp file entirely when not compiling for Windows. I'm not sure that's what we do for other platforms though so I didn't go for that, but I'm also fine with that approach.

@ldionne ldionne merged commit 25a2d51 into llvm:main Nov 5, 2023
@ldionne ldionne deleted the review/guard-print-with-win32 branch November 5, 2023 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants