[libcxx-commits] [libcxx] [libc++] Add [[gnu::const/pure]] to a few locale functions (PR #121438)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 1 07:34:08 PST 2025


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

This allows the compiler to merge or drop calls to these functions in some cases.


>From ef0cfaa6c3b54e079e6025a50a126f0c49c6d085 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 1 Jan 2025 16:33:08 +0100
Subject: [PATCH] [libc++] Add [[gnu::const/pure]] to a few locale functions

---
 libcxx/include/__locale | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index b675e01bac81e5..7debac72c6e6bb 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -93,7 +93,7 @@ public:
 
   // global locale objects:
   static locale global(const locale&);
-  static const locale& classic();
+  [[__gnu__::__const__]] static const locale& classic();
 
 private:
   class __imp;
@@ -105,8 +105,8 @@ private:
 
   void __install_ctor(const locale&, facet*, long);
   static locale& __global();
-  bool has_facet(id&) const;
-  const facet* use_facet(id&) const;
+  [[__gnu__::__pure__]] bool has_facet(id&) const;
+  [[__gnu__::__pure__]] const facet* use_facet(id&) const;
 
   template <class _Facet>
   friend bool has_facet(const locale&) _NOEXCEPT;



More information about the libcxx-commits mailing list