[libcxx-commits] [libcxx] e31d27e - [libc++][format] Renames __null_sentinel.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sat Dec 17 04:43:58 PST 2022


Author: Mark de Wever
Date: 2022-12-17T13:43:52+01:00
New Revision: e31d27e46048ccc3294d6b215dc778b3390e7834

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

LOG: [libc++][format] Renames __null_sentinel.

While the FreeBSD CI was enabled in D128084 it was discovered libc++
uses the name of a system macro on FreeBSD. This renames the macro to
fix the issue.

Reviewed By: emaste, #libc, philnik

Differential Revision: https://reviews.llvm.org/D140117

Added: 
    

Modified: 
    libcxx/include/__format/formatter_output.h
    libcxx/test/libcxx/nasty_macros.compile.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__format/formatter_output.h b/libcxx/include/__format/formatter_output.h
index 4f2c0445c02e..adef574c3f45 100644
--- a/libcxx/include/__format/formatter_output.h
+++ b/libcxx/include/__format/formatter_output.h
@@ -373,10 +373,10 @@ _LIBCPP_HIDE_FROM_ABI auto __write_string(
 
 #  if _LIBCPP_STD_VER > 20
 
-struct __null_sentinel {};
+struct __nul_terminator {};
 
 template <class _CharT>
-_LIBCPP_HIDE_FROM_ABI bool operator==(const _CharT* __cstr, __null_sentinel) {
+_LIBCPP_HIDE_FROM_ABI bool operator==(const _CharT* __cstr, __nul_terminator) {
   return *__cstr == _CharT('\0');
 }
 
@@ -384,7 +384,7 @@ template <class _CharT>
 _LIBCPP_HIDE_FROM_ABI void
 __write_escaped_code_unit(basic_string<_CharT>& __str, char32_t __value, const _CharT* __prefix) {
   back_insert_iterator __out_it{__str};
-  std::ranges::copy(__prefix, __null_sentinel{}, __out_it);
+  std::ranges::copy(__prefix, __nul_terminator{}, __out_it);
 
   char __buffer[8];
   to_chars_result __r = std::to_chars(std::begin(__buffer), std::end(__buffer), __value, 16);

diff  --git a/libcxx/test/libcxx/nasty_macros.compile.pass.cpp b/libcxx/test/libcxx/nasty_macros.compile.pass.cpp
index d2d875f955b7..93c54a4b74c8 100644
--- a/libcxx/test/libcxx/nasty_macros.compile.pass.cpp
+++ b/libcxx/test/libcxx/nasty_macros.compile.pass.cpp
@@ -59,6 +59,11 @@
 # undef _M
 #endif
 
+// Test that libc++ doesn't use names that collide with FreeBSD system macros.
+#ifndef __FreeBSD__
+#  define __null_sentinel NASTY_MACRO
+#endif
+
 // tchar.h defines these macros on Windows
 #ifndef _WIN32
 # define _UI   NASTY_MACRO


        


More information about the libcxx-commits mailing list