Skip to content

Commit 6c2151b

Browse files
committed
[cmake] Disable GCC 9's -Winit-list-lifetime warning in ArrayRef
Summary: This is a new warning which fires when one stores a reference to the initializer_list contents in a way which may outlive the initializer_list which it came from. In llvm this warning is triggered whenever someone uses the initializer_list ArrayRef constructor. This is indeed a dangerous thing to do (I myself was bitten by that at least once), but it is not more dangerous than calling other ArrayRef constructors with temporary objects -- something which we are used to and have accepted as a tradeoff for ArrayRef's efficiency. Currently, this warnings generates so much output that it completely obscures any actionable warnings, so this patch disables it. Reviewers: rnk, aaron.ballman Subscribers: mgorny, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70122
1 parent b81cc60 commit 6c2151b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

llvm/include/llvm/ADT/ArrayRef.h

+10
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,19 @@ namespace llvm {
9797
/*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}
9898

9999
/// Construct an ArrayRef from a std::initializer_list.
100+
#if LLVM_GNUC_PREREQ(9, 0, 0)
101+
// Disable gcc's warning in this constructor as it generates an enormous amount
102+
// of messages. Anyone using ArrayRef should already be aware of the fact that
103+
// it does not do lifetime extension.
104+
#pragma GCC diagnostic push
105+
#pragma GCC diagnostic ignored "-Winit-list-lifetime"
106+
#endif
100107
/*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
101108
: Data(Vec.begin() == Vec.end() ? (T*)nullptr : Vec.begin()),
102109
Length(Vec.size()) {}
110+
#if LLVM_GNUC_PREREQ(9, 0, 0)
111+
#pragma GCC diagnostic pop
112+
#endif
103113

104114
/// Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses SFINAE to
105115
/// ensure that only ArrayRefs of pointers can be converted.

0 commit comments

Comments
 (0)