Skip to content

Conversation

kazutakahirata
Copy link
Contributor

In C++17 and later, "return {A, B};" guarantees copy elision for a
std::pair return type, ensuring the object is constructed directly in
the return slot. This patch updates those instances under ADT/.

In C++17 and later, "return {A, B};" guarantees copy elision for a
std::pair return type, ensuring the object is constructed directly in
the return slot.  This patch updates those instances under ADT/.
@llvmbot
Copy link
Member

llvmbot commented Sep 23, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

In C++17 and later, "return {A, B};" guarantees copy elision for a
std::pair return type, ensuring the object is constructed directly in
the return slot. This patch updates those instances under ADT/.


Full diff: https://github.com/llvm/llvm-project/pull/160238.diff

4 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMapInfo.h (+2-4)
  • (modified) llvm/include/llvm/ADT/STLExtras.h (+1-1)
  • (modified) llvm/include/llvm/ADT/SparseMultiSet.h (+1-1)
  • (modified) llvm/include/llvm/ADT/StringRef.h (+4-4)
diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index 57a8674e35015..f24aeb4371e7f 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -139,13 +139,11 @@ struct DenseMapInfo<std::pair<T, U>> {
   using SecondInfo = DenseMapInfo<U>;
 
   static constexpr Pair getEmptyKey() {
-    return std::make_pair(FirstInfo::getEmptyKey(),
-                          SecondInfo::getEmptyKey());
+    return {FirstInfo::getEmptyKey(), SecondInfo::getEmptyKey()};
   }
 
   static constexpr Pair getTombstoneKey() {
-    return std::make_pair(FirstInfo::getTombstoneKey(),
-                          SecondInfo::getTombstoneKey());
+    return {FirstInfo::getTombstoneKey(), SecondInfo::getTombstoneKey()};
   }
 
   static unsigned getHashValue(const Pair& PairVal) {
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 4e7e42e9f4a5f..4a91b061dd3b7 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1371,7 +1371,7 @@ class indexed_accessor_range
   offset_base(const std::pair<BaseT, ptrdiff_t> &base, ptrdiff_t index) {
     // We encode the internal base as a pair of the derived base and a start
     // index into the derived base.
-    return std::make_pair(base.first, base.second + index);
+    return {base.first, base.second + index};
   }
   /// See `detail::indexed_accessor_range_base` for details.
   static ReferenceT
diff --git a/llvm/include/llvm/ADT/SparseMultiSet.h b/llvm/include/llvm/ADT/SparseMultiSet.h
index cf7603158b28b..0aa7edbcea673 100644
--- a/llvm/include/llvm/ADT/SparseMultiSet.h
+++ b/llvm/include/llvm/ADT/SparseMultiSet.h
@@ -400,7 +400,7 @@ class SparseMultiSet {
   RangePair equal_range(const KeyT &K) {
     iterator B = find(K);
     iterator E = iterator(this, SMSNode::INVALID, B.SparseIdx);
-    return std::make_pair(B, E);
+    return {B, E};
   }
 
   /// Insert a new element at the tail of the subset list. Returns an iterator
diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 49a52fbe1a6f7..7aee2aa67ddec 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -717,8 +717,8 @@ namespace llvm {
     split(StringRef Separator) const {
       size_t Idx = find(Separator);
       if (Idx == npos)
-        return std::make_pair(*this, StringRef());
-      return std::make_pair(slice(0, Idx), substr(Idx + Separator.size()));
+        return {*this, StringRef()};
+      return {slice(0, Idx), substr(Idx + Separator.size())};
     }
 
     /// Split into two substrings around the last occurrence of a separator
@@ -735,8 +735,8 @@ namespace llvm {
     rsplit(StringRef Separator) const {
       size_t Idx = rfind(Separator);
       if (Idx == npos)
-        return std::make_pair(*this, StringRef());
-      return std::make_pair(slice(0, Idx), substr(Idx + Separator.size()));
+        return {*this, StringRef()};
+      return {slice(0, Idx), substr(Idx + Separator.size())};
     }
 
     /// Split into substrings around the occurrences of a separator string.

@kazutakahirata kazutakahirata merged commit c2fe408 into llvm:main Sep 23, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250922_ADT_guaranteed_copy_elision branch September 23, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants