[libcxx-commits] [libcxx] [libc++] Make bad_function_call::what() existance a matter of availability instead of ABI (PR #127697)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 18 13:09:24 PST 2025


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/127697

We're currently adding `bad_function_call::what()` behind an ABI flag, even though adding it is not an ABI break and can be handled through availability.


>From 5c825df6420dbd813bd1a034192d5b72b2f321e4 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 18 Feb 2025 22:07:46 +0100
Subject: [PATCH] [libc++] Make bad_function_call::what() existance a matter of
 availability instead of ABI

---
 libcxx/include/__configuration/availability.h | 10 ++++++++++
 libcxx/include/__functional/function.h        |  2 +-
 libcxx/src/functional.cpp                     |  2 --
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__configuration/availability.h b/libcxx/include/__configuration/availability.h
index 261cf9c1ae9d8..bdb72d86c2603 100644
--- a/libcxx/include/__configuration/availability.h
+++ b/libcxx/include/__configuration/availability.h
@@ -78,6 +78,9 @@
 // in all versions of the library are available.
 #if !_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS
 
+#  define _LIBCPP_INTRODUCED_IN_LLVM_21 1
+#  define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE /* nothing */
+
 #  define _LIBCPP_INTRODUCED_IN_LLVM_20 1
 #  define _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE /* nothing */
 
@@ -114,6 +117,11 @@
 
 // clang-format off
 
+// LLVM 21
+// TODO: Fill this in
+#  define _LIBCPP_INTRODUCED_IN_LLVM_21 0
+#  define _LIBCPP_INTRODUCED_IN_LLVM_21_ATTRIBUTE __attribute__((unavailable))
+
 // LLVM 20
 // TODO: Fill this in
 #  define _LIBCPP_INTRODUCED_IN_LLVM_20 0
@@ -359,6 +367,8 @@
 #define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20
 #define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT _LIBCPP_INTRODUCED_IN_LLVM_20_ATTRIBUTE
 
+#define _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE _LIBCPP_INTRODUCED_IN_LLVM_21
+
 // Define availability attributes that depend on _LIBCPP_HAS_EXCEPTIONS.
 // Those are defined in terms of the availability attributes above, and
 // should not be vendor-specific.
diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h
index 2a1293cfcc26b..cd77012173512 100644
--- a/libcxx/include/__functional/function.h
+++ b/libcxx/include/__functional/function.h
@@ -71,7 +71,7 @@ class _LIBCPP_EXPORTED_FROM_ABI bad_function_call : public exception {
   _LIBCPP_HIDE_FROM_ABI_VIRTUAL ~bad_function_call() _NOEXCEPT override {}
 #  endif
 
-#  ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
+#  if _LIBCPP_AVAILABILITY_HAS_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
   const char* what() const _NOEXCEPT override;
 #  endif
 };
diff --git a/libcxx/src/functional.cpp b/libcxx/src/functional.cpp
index ef53e3e84da0e..f2c70fc54392d 100644
--- a/libcxx/src/functional.cpp
+++ b/libcxx/src/functional.cpp
@@ -12,8 +12,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 bad_function_call::~bad_function_call() noexcept {}
 
-#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE
 const char* bad_function_call::what() const noexcept { return "std::bad_function_call"; }
-#endif
 
 _LIBCPP_END_NAMESPACE_STD



More information about the libcxx-commits mailing list