[llvm] 100582e - Pass std::initializer_list by value to ArrayRef constructor. (#113590)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 24 10:27:42 PDT 2024


Author: Haojian Wu
Date: 2024-10-24T19:27:38+02:00
New Revision: 100582ed4f5189c661c365e1ba8b07eb3af0f844

URL: https://github.com/llvm/llvm-project/commit/100582ed4f5189c661c365e1ba8b07eb3af0f844
DIFF: https://github.com/llvm/llvm-project/commit/100582ed4f5189c661c365e1ba8b07eb3af0f844.diff

LOG: Pass std::initializer_list by value to ArrayRef constructor. (#113590)

The std::initializer_list is a lightweight object, it is passed by value
in general.

This would also avoid a false positive when adding the lifetimebound
annotation (#113547)

```
ArrayRef<int> foo(std::initializer_list<int> list) {
  return ArrayRef<int>(list);
}
```

Added: 
    

Modified: 
    llvm/include/llvm/ADT/ArrayRef.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index d9897320ce091a..bf6b55923b84ba 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -113,7 +113,7 @@ namespace llvm {
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Winit-list-lifetime"
 #endif
-    constexpr /*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
+    constexpr /*implicit*/ ArrayRef(std::initializer_list<T> Vec)
         : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()),
           Length(Vec.size()) {}
 #if LLVM_GNUC_PREREQ(9, 0, 0)


        


More information about the llvm-commits mailing list