1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/memory/checked_ptr.h" 6 7 class MyClass { 8 // Lambdas are backed by a class that may have (depending on what the lambda 9 // captures) pointer fields. The rewriter should ignore such fields (since 10 // they don't have an equivalent in source code). foo()11 void foo() { 12 int x = 123; 13 14 // No rewrite expected in the two lamdas below. 15 auto lambda1 = [this]() -> int { return 123; }; 16 auto lambda2 = [&]() -> int { return x; }; 17 18 // Nested structs defined within a lambda should be rewritten. This test 19 // helps ensure that |implicit_field_decl_matcher| uses |hasParent| to match 20 // |isLambda|, rather than |hasAncestor|. 21 auto lambda = [&]() -> int { 22 struct NestedStruct { 23 // Expected rewrite: CheckedPtr<int> ptr_field; 24 CheckedPtr<int> ptr_field; 25 } var; 26 var.ptr_field = &x; 27 28 return x; 29 }; 30 } 31 }; 32