Skip to content

Commit 3247dca

Browse files
RepeatedPtrIterator is a view type
After llvm/llvm-project#177660, Clang tracks iterator lifetimes through transparent functions (like .begin(), operator*) and allows to detect the following case: ```cpp const UafSubProto* ReturnSubProtoFromForLoop(bool condition) { const UafSubProto* p = nullptr; UafProto proto; for (const UafSubProto& sub_proto : proto.repeated_sub_protos()) { // expected-error {{address of stack memory is returned later}} if (condition) { return &sub_proto; // expected-note {{returned here}} } } for (const UafSubProto& sub_proto : proto.repeated_sub_protos()) { // expected-error {{address of stack memory is returned later}} if (condition) { p = &sub_proto; return p; // expected-note {{returned here}} } } return p; } ``` PiperOrigin-RevId: 865027461
1 parent 0dd552c commit 3247dca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/google/protobuf/repeated_ptr_field.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ class RustRepeatedMessageHelper {
19801980
// This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin
19811981
// (jyasskin@google.com).
19821982
template <typename Element>
1983-
class RepeatedPtrIterator {
1983+
class ABSL_ATTRIBUTE_VIEW RepeatedPtrIterator {
19841984
public:
19851985
using iterator = RepeatedPtrIterator<Element>;
19861986
using iterator_category = std::random_access_iterator_tag;

0 commit comments

Comments
 (0)