From 76e40808a1f9b5dd2f15c4e2d23777bcbf745db2 Mon Sep 17 00:00:00 2001 From: TJ Yin Date: Sun, 23 Aug 2020 13:10:01 -0700 Subject: [PATCH] add missing include file Summary: Without this, we couldn't include `for_each.h` before generated `_for_each_field.h`. Otherwise it's build-error due to missing type. Reviewed By: iahs Differential Revision: D23250681 fbshipit-source-id: 70455a2b1c0be919c253ded55ed3b982a2ea8d0e --- thrift/lib/cpp2/visitation/metadata.h | 1 + ...visitation_for_each_include_order_test.cpp | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 thrift/test/visitation_for_each_include_order_test.cpp diff --git a/thrift/lib/cpp2/visitation/metadata.h b/thrift/lib/cpp2/visitation/metadata.h index 99570038769..89cb01be411 100644 --- a/thrift/lib/cpp2/visitation/metadata.h +++ b/thrift/lib/cpp2/visitation/metadata.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include namespace apache { diff --git a/thrift/test/visitation_for_each_include_order_test.cpp b/thrift/test/visitation_for_each_include_order_test.cpp new file mode 100644 index 00000000000..f8801fc2a8a --- /dev/null +++ b/thrift/test/visitation_for_each_include_order_test.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Test whether it works if we include for_each.h first. +#include + +#include + +#include +#include + +using namespace apache::thrift; +using namespace test_cpp2::cpp_reflection; + +TEST(structA, test) { + structA s; + s.a_ref() = 1; + s.b_ref() = "1"; + for_each_field(s, [](auto&&, auto ref) { + EXPECT_EQ(folly::to(*ref), "1"); + ref = folly::to(2); + }); + EXPECT_EQ(s.a_ref(), 2); + EXPECT_EQ(s.b_ref(), "2"); +}