[gcc r16-7153] libstdc++: Fix use of feature test macro in <source_location>
Jonathan Wakely
redi@gcc.gnu.org
Thu Jan 29 17:19:05 GMT 2026
https://gcc.gnu.org/g:a111fd4d47243b7b9a9daabbc79fd4a2c7339dd4
commit r16-7153-ga111fd4d47243b7b9a9daabbc79fd4a2c7339dd4
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Jan 29 17:02:43 2026 +0000
libstdc++: Fix use of feature test macro in <source_location>
libstdc++-v3/ChangeLog:
* include/std/source_location: Check __glibcxx_contracts instead
of __cpp_lib_contracts.
* testsuite/18_support/contracts/includes.cc: New test.
Diff:
---
libstdc++-v3/include/std/source_location | 13 +++++--------
libstdc++-v3/testsuite/18_support/contracts/includes.cc | 6 ++++++
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/libstdc++-v3/include/std/source_location b/libstdc++-v3/include/std/source_location
index 170753fdde2a..f773879755c9 100644
--- a/libstdc++-v3/include/std/source_location
+++ b/libstdc++-v3/include/std/source_location
@@ -38,12 +38,9 @@
namespace std
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
-#ifdef __cpp_lib_contracts
- namespace contracts
- {
- class contract_violation;
- }
-#endif // __cpp_lib_contracts
+#ifdef __glibcxx_contracts
+ namespace contracts { class contract_violation; }
+#endif
/// A class that describes a location in source code.
struct source_location
@@ -95,10 +92,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr source_location (const void *__t)
: _M_impl (static_cast <const __impl*>(__t)) {}
-#ifdef __cpp_lib_contracts
+#ifdef __glibcxx_contracts
/* To enable use of the source __impl*. */
friend class std::contracts::contract_violation;
-#endif // __cpp_lib_contracts
+#endif
};
_GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/testsuite/18_support/contracts/includes.cc b/libstdc++-v3/testsuite/18_support/contracts/includes.cc
new file mode 100644
index 000000000000..91f793f1e201
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/contracts/includes.cc
@@ -0,0 +1,6 @@
+// { dg-options "-fcontracts" }
+// { dg-do compile { target c++26 } }
+
+// We should not get errors from including this before <contracts>:
+#include <source_location>
+#include <contracts>
More information about the Libstdc++-cvs
mailing list