[libcxx-commits] [libcxx] 1c4b31c - [libc++] Improve error messages for disabled modes

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 20 06:37:04 PDT 2022


Author: Louis Dionne
Date: 2022-05-20T09:36:55-04:00
New Revision: 1c4b31c38b3c36d6e6bbb071ce66abfa52d64c10

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

LOG: [libc++] Improve error messages for disabled modes

We should not surface CMake-level options like LIBCXX_ENABLE_FILESYSTEM
to our users, since they don't know what it means. Instead, use a slightly
more general wording.

Also, add an error in <ios> to improve the quality of errors for people
trying to use <iostream> when localization is disabled.

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

Added: 
    

Modified: 
    libcxx/include/barrier
    libcxx/include/filesystem
    libcxx/include/future
    libcxx/include/ios
    libcxx/include/latch
    libcxx/include/locale.h
    libcxx/include/semaphore
    libcxx/include/shared_mutex
    libcxx/include/thread

Removed: 
    


################################################################################
diff  --git a/libcxx/include/barrier b/libcxx/include/barrier
index 6f8a1f9f38be..36ea6f589d7e 100644
--- a/libcxx/include/barrier
+++ b/libcxx/include/barrier
@@ -59,7 +59,7 @@ namespace std
 #endif
 
 #ifdef _LIBCPP_HAS_NO_THREADS
-# error <barrier> is not supported on this single threaded system
+# error "<barrier> is not supported since libc++ has been configured without support for threads."
 #endif
 
 _LIBCPP_PUSH_MACROS

diff  --git a/libcxx/include/filesystem b/libcxx/include/filesystem
index c23cac9828b1..fd20ec44576b 100644
--- a/libcxx/include/filesystem
+++ b/libcxx/include/filesystem
@@ -261,7 +261,7 @@ inline constexpr bool std::ranges::enable_view<std::filesystem::recursive_direct
 #include <version>
 
 #if defined(_LIBCPP_HAS_NO_FILESYSTEM_LIBRARY)
-# error "The Filesystem library is not supported since libc++ has been configured with LIBCXX_ENABLE_FILESYSTEM disabled"
+# error "The <filesystem> library is not supported since libc++ has been configured without support for a filesystem."
 #endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/future b/libcxx/include/future
index b39747792261..4f49bf158bac 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -383,8 +383,8 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #endif
 
 #ifdef _LIBCPP_HAS_NO_THREADS
-#error <future> is not supported on this single threaded system
-#else // !_LIBCPP_HAS_NO_THREADS
+# error "<future> is not supported since libc++ has been configured without support for threads."
+#endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -2432,6 +2432,4 @@ future<void>::share() _NOEXCEPT
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !_LIBCPP_HAS_NO_THREADS
-
 #endif // _LIBCPP_FUTURE

diff  --git a/libcxx/include/ios b/libcxx/include/ios
index a790ba5c1775..d1b8c43a8ac9 100644
--- a/libcxx/include/ios
+++ b/libcxx/include/ios
@@ -210,8 +210,13 @@ storage-class-specifier const error_category& iostream_category() noexcept;
 
 */
 
-#include <__assert> // all public C++ headers provide the assertion handler
 #include <__config>
+
+#if defined(_LIBCPP_HAS_NO_LOCALIZATION)
+#   error "The iostreams library is not supported since libc++ has been configured without support for localization."
+#endif
+
+#include <__assert> // all public C++ headers provide the assertion handler
 #include <__ios/fpos.h>
 #include <__locale>
 #include <__utility/swap.h>

diff  --git a/libcxx/include/latch b/libcxx/include/latch
index d6cb47622268..21abbad2171f 100644
--- a/libcxx/include/latch
+++ b/libcxx/include/latch
@@ -51,7 +51,7 @@ namespace std
 #endif
 
 #ifdef _LIBCPP_HAS_NO_THREADS
-# error <latch> is not supported on this single threaded system
+# error "<latch> is not supported since libc++ has been configured without support for threads."
 #endif
 
 _LIBCPP_PUSH_MACROS

diff  --git a/libcxx/include/locale.h b/libcxx/include/locale.h
index 3a05c18abb73..17c0a705a009 100644
--- a/libcxx/include/locale.h
+++ b/libcxx/include/locale.h
@@ -36,7 +36,7 @@
 #include <__config>
 
 #if defined(_LIBCPP_HAS_NO_LOCALIZATION)
-#   error "The Localization library is not supported since libc++ has been configured with LIBCXX_ENABLE_LOCALIZATION disabled"
+#   error "<locale.h> is not supported since libc++ has been configured without support for localization."
 #endif
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

diff  --git a/libcxx/include/semaphore b/libcxx/include/semaphore
index b174eba34dbc..ce1fa6987c4a 100644
--- a/libcxx/include/semaphore
+++ b/libcxx/include/semaphore
@@ -59,7 +59,7 @@ using binary_semaphore = counting_semaphore<1>;
 #endif
 
 #ifdef _LIBCPP_HAS_NO_THREADS
-# error <semaphore> is not supported on this single threaded system
+# error "<semaphore> is not supported since libc++ has been configured without support for threads."
 #endif
 
 _LIBCPP_PUSH_MACROS

diff  --git a/libcxx/include/shared_mutex b/libcxx/include/shared_mutex
index 68a2bbae0f53..a089aa9fa817 100644
--- a/libcxx/include/shared_mutex
+++ b/libcxx/include/shared_mutex
@@ -140,8 +140,8 @@ _LIBCPP_PUSH_MACROS
 #endif
 
 #ifdef _LIBCPP_HAS_NO_THREADS
-#error <shared_mutex> is not supported on this single threaded system
-#else // !_LIBCPP_HAS_NO_THREADS
+# error "<shared_mutex> is not supported since libc++ has been configured without support for threads."
+#endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -501,8 +501,6 @@ swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) _NOEXCEPT
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !_LIBCPP_HAS_NO_THREADS
-
 #endif // _LIBCPP_STD_VER > 11
 
 _LIBCPP_POP_MACROS

diff  --git a/libcxx/include/thread b/libcxx/include/thread
index 837ee4a9972e..20708f119c96 100644
--- a/libcxx/include/thread
+++ b/libcxx/include/thread
@@ -105,8 +105,8 @@ _LIBCPP_PUSH_MACROS
 #include <__undef_macros>
 
 #ifdef _LIBCPP_HAS_NO_THREADS
-#error <thread> is not supported on this single threaded system
-#else // !_LIBCPP_HAS_NO_THREADS
+# error "<thread> is not supported since libc++ has been configured without support for threads."
+#endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -401,8 +401,6 @@ void yield() _NOEXCEPT {__libcpp_thread_yield();}
 
 _LIBCPP_END_NAMESPACE_STD
 
-#endif // !_LIBCPP_HAS_NO_THREADS
-
 _LIBCPP_POP_MACROS
 
 #endif // _LIBCPP_THREAD


        


More information about the libcxx-commits mailing list