Skip to content

Commit 8a3554c

Browse files
tamirdRebase bot
authored andcommitted
[sdk][fidl][fpromise][fit] Add Wctad-maybe-unsupported
Bug: 120888 Fixed: 127411 Change-Id: If008aaad4d5a2e9906caac89dc350fb05cadfa19 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/871384 Reviewed-by: Adam Barth <[email protected]> Commit-Queue: Auto-Submit <[email protected]> Fuchsia-Auto-Submit: Tamir Duberstein <[email protected]> API-Review: Adam Barth <[email protected]> Reviewed-by: Yifei Teng <[email protected]>
1 parent bf3c3cc commit 8a3554c

File tree

10 files changed

+56
-30
lines changed

10 files changed

+56
-30
lines changed

build/cpp/fidl_cpp.gni

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,14 @@ template("_fidl_cpp_library_impl") {
193193
}
194194
}
195195

196-
# TODO(fxbug.dev/120888): Remove `-Wshadow` when the flag is on
197-
# by default.
198-
cflags_cc = [ "-Wshadow" ]
196+
# chromium uses this library, and enables the following flags, so these tests should work with
197+
# these flags enabled.
198+
#
199+
# TODO(fxbug.dev/120888): Remove this when a central definition of SDK warnings exists.
200+
cflags_cc = [
201+
"-Wctad-maybe-unsupported",
202+
"-Wshadow",
203+
]
199204

200205
if (defined(invoker.additional_configs)) {
201206
configs += invoker.additional_configs

sdk/lib/fidl/cpp/wire/fidl_cpp_wire.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/intrusive_container/wavl_tree.h": "39eb6d96e5d7c7a1b47930cea85a962f",
2727
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/intrusive_container/wavl_tree_internal.h": "83b29df78e334e1325d9d94198924239",
2828
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/make_response_context.h": "f6cc02ff60043349d7ec40f2ee102185",
29-
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/server_details.h": "d159958fdd9649751ab5e30fa50b4cfd",
29+
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/server_details.h": "e5cad36202de5551b2cb4a728d189986",
3030
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/synchronization_checker.h": "4c143e8c9eb85bb4cf0e2c35d3d9cd0a",
3131
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/thenable.h": "3f0ac164703381f05766132068212c9e",
3232
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/internal/transport.h": "bd1b299b9195bbdf08404e358145d828",
@@ -48,7 +48,7 @@
4848
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/unknown_interactions.h": "99780ed73d3adb008df831471be863f0",
4949
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/vector_view.h": "ebf5e1ff94685e75754951171d0e5f62",
5050
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/wire_coding_common.h": "88c316337c33da9e26199727b3c44846",
51-
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/wire_coding_traits.h": "b1afa52f6cac7a91f23528510f1aafa7",
51+
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/wire_coding_traits.h": "5840215fa8b4d35f6efe62c08210d9f3",
5252
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/wire_decoder.h": "df97148cc05ecad3e208ee754a45a837",
5353
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/wire_encoder.h": "1fa6397c5a1dc207d805a7c6d18a616f",
5454
"pkg/fidl_cpp_wire/include/lib/fidl/cpp/wire/wire_messaging.h": "46008354c21f3d47e311213ac75313e7",

sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/internal/server_details.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ struct UnboundThunk {
387387
std::remove_reference_t<OnUnbound> on_unbound_;
388388
};
389389

390+
// This suppresses the '-Wctad-maybe-unsupported' compiler warning when CTAD is used.
391+
//
392+
// See https://github.com/llvm/llvm-project/blob/42874f6/libcxx/include/__config#L1259-L1261.
393+
template <class... Tag>
394+
UnboundThunk(typename Tag::__allow_ctad...) -> UnboundThunk<Tag...>;
395+
390396
} // namespace internal
391397

392398
} // namespace fidl

sdk/lib/fidl/cpp/wire/include/lib/fidl/cpp/wire/wire_coding_traits.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void WireCheckPadding(WireDecoder* decoder, WirePosition position, MaskType mask
8080

8181
template <typename T, bool IsRecursive>
8282
struct WireCodingTraits<T, WireCodingConstraintEmpty, IsRecursive,
83-
typename std::enable_if<IsPrimitive<T>::value>::type> {
83+
std::enable_if_t<IsPrimitive<T>::value>> {
8484
static constexpr size_t inline_size = sizeof(T);
8585
static constexpr bool is_memcpy_compatible = true;
8686

@@ -104,7 +104,7 @@ struct WireCodingTraits<bool, WireCodingConstraintEmpty, IsRecursive> {
104104
static void Decode(WireDecoder* decoder, WirePosition position,
105105
RecursionDepth<IsRecursive> recursion_depth) {
106106
uint8_t uintval = *position.As<uint8_t>();
107-
if (unlikely(!(uintval == 0 || uintval == 1))) {
107+
if (unlikely(uintval != 0 && uintval != 1)) {
108108
decoder->SetError(kCodingErrorInvalidBoolean);
109109
return;
110110
}
@@ -200,7 +200,7 @@ struct VectorCodingTraitHelper {
200200
DecodePrework(decoder, position, Constraint::is_optional, Constraint::limit)) {
201201
return;
202202
}
203-
RecursionDepth inner_depth = recursion_depth.Add(decoder, 1);
203+
RecursionDepth<IsRecursive> inner_depth = recursion_depth.Add(decoder, 1);
204204
if (!inner_depth.IsValid()) {
205205
return;
206206
}
@@ -341,7 +341,7 @@ struct WireCodingTraits<fidl::Array<T, N>, Constraint, IsRecursive> {
341341
#ifdef __Fuchsia__
342342
template <typename T, typename Constraint, bool IsRecursive>
343343
struct WireCodingTraits<T, Constraint, IsRecursive,
344-
typename std::enable_if<std::is_base_of<zx::object_base, T>::value>::type> {
344+
std::enable_if_t<std::is_base_of_v<zx::object_base, T>>> {
345345
static constexpr size_t inline_size = sizeof(zx_handle_t);
346346
static constexpr bool is_memcpy_compatible = false;
347347

sdk/lib/fit-promise/fit-promise.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"pkg/fit-promise/include/lib/fpromise/barrier.h": "165eaf8820b9055c94adc5199c9a496d",
3-
"pkg/fit-promise/include/lib/fpromise/bridge.h": "5261dd8f50f207091d4d3cf3cc079c01",
3+
"pkg/fit-promise/include/lib/fpromise/bridge.h": "092502f25421c313acba8fd7aeda3f14",
44
"pkg/fit-promise/include/lib/fpromise/bridge_internal.h": "7f17672771d4eaebe75c5e4d9a3e216a",
55
"pkg/fit-promise/include/lib/fpromise/promise.h": "0a5b184d842ff4d8cf3110372e8a0dfa",
66
"pkg/fit-promise/include/lib/fpromise/promise_internal.h": "ebb8a10a0da343651d1903a2c99954c3",

sdk/lib/fit-promise/include/lib/fpromise/bridge.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ class bridge final {
161161
consumer_type consumer;
162162
};
163163

164+
// This suppresses the '-Wctad-maybe-unsupported' compiler warning when CTAD is used.
165+
//
166+
// See https://github.com/llvm/llvm-project/blob/42874f6/libcxx/include/__config#L1259-L1261.
167+
template <class... Tag>
168+
bridge(typename Tag::__allow_ctad...) -> bridge<Tag...>;
169+
164170
// Provides a result upon completion of an asynchronous task.
165171
//
166172
// Instances of this class have single-ownership of a unique capability for

sdk/lib/fit-promise/tests/BUILD.gn

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@ test("fit-promise-tests") {
3737
"//sdk/lib/fit-promise",
3838
"//zircon/system/ulib/zxtest",
3939
]
40-
configs += [ ":shadow" ]
40+
configs += [ ":sdk" ]
4141
if (is_fuchsia) {
4242
deps += [ "//sdk/lib/fdio" ]
4343
}
4444
}
4545

46-
config("shadow") {
47-
# chromium uses this library, and enables the following flag,
48-
# so these tests should work with this flag enabled
49-
cflags_cc = [ "-Wshadow" ]
46+
# chromium uses this library, and enables the following flags, so these tests should work with these
47+
# flags enabled.
48+
#
49+
# TODO(fxbug.dev/120888): Remove this when a central definition of SDK warnings exists.
50+
config("sdk") {
51+
cflags_cc = [
52+
"-Wctad-maybe-unsupported",
53+
"-Wshadow",
54+
]
5055
}
5156

5257
fuchsia_unittest_package("fit-promise-test-pkg") {

sdk/lib/fit/test/BUILD.gn

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test("fit-unittest") {
2828
"//sdk/lib/fit",
2929
"//zircon/system/ulib/zxtest",
3030
]
31-
configs += [ ":shadow" ]
31+
configs += [ ":sdk" ]
3232
if (is_fuchsia) {
3333
deps += [ "//sdk/lib/fdio" ]
3434
}
@@ -60,16 +60,21 @@ test("fit") {
6060
"//sdk/lib/fit",
6161
"//zircon/system/ulib/zxtest",
6262
]
63-
configs += [ ":shadow" ]
63+
configs += [ ":sdk" ]
6464
if (is_fuchsia) {
6565
deps += [ "//sdk/lib/fdio" ]
6666
}
6767
}
6868

69-
config("shadow") {
70-
# chromium uses this library, and enables the following flag,
71-
# so these tests should work with this flag enabled
72-
cflags_cc = [ "-Wshadow" ]
69+
# chromium uses this library, and enables the following flags, so these tests should work with these
70+
# flags enabled.
71+
#
72+
# TODO(fxbug.dev/120888): Remove this when a central definition of SDK warnings exists.
73+
config("sdk") {
74+
cflags_cc = [
75+
"-Wctad-maybe-unsupported",
76+
"-Wshadow",
77+
]
7378
}
7479

7580
fuchsia_unittest_package("fit-test-pkg") {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"pkg/fidl_cpp_natural_ostream/include/lib/fidl/cpp/natural_ostream.h": "8ac5e357f4a25064556cede9269e8892"
2+
"pkg/fidl_cpp_natural_ostream/include/lib/fidl/cpp/natural_ostream.h": "df2ba72ab56b91148d648d5a91c11f1c"
33
}

src/lib/fidl/cpp/include/lib/fidl/cpp/natural_ostream.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ struct Formatted {
3333
const T& value;
3434
};
3535

36+
template <typename T>
37+
Formatted(const T& v) -> Formatted<T>;
38+
3639
template <typename T, typename = void>
3740
struct Formatter;
3841

@@ -92,9 +95,8 @@ struct Formatter<std::optional<std::string>> {
9295
static std::ostream& Format(std::ostream& os, const std::optional<std::string>& value) {
9396
if (value.has_value()) {
9497
return Formatter<std::string>::Format(os, value.value());
95-
} else {
96-
return os << "null";
9798
}
99+
return os << "null";
98100
}
99101
};
100102

@@ -182,9 +184,8 @@ struct Formatter<std::optional<std::vector<T>>> {
182184
static std::ostream& Format(std::ostream& os, const std::optional<std::vector<T>>& value) {
183185
if (value.has_value()) {
184186
return Formatter<std::vector<T>>::Format(os, value.value());
185-
} else {
186-
return os << "null";
187187
}
188+
return os << "null";
188189
}
189190
};
190191

@@ -205,9 +206,8 @@ struct Formatter<std::optional<T>> {
205206
static std::ostream& Format(std::ostream& os, const std::optional<T>& value) {
206207
if (value.has_value()) {
207208
return Formatter<T>::Format(os, value.value());
208-
} else {
209-
return os << "null";
210209
}
210+
return os << "null";
211211
}
212212
};
213213

@@ -216,9 +216,8 @@ struct Formatter<fidl::Box<T>> {
216216
static std::ostream& Format(std::ostream& os, const fidl::Box<T>& value) {
217217
if (value) {
218218
return Formatter<T>::Format(os, *value);
219-
} else {
220-
return os << "null";
221219
}
220+
return os << "null";
222221
}
223222
};
224223

0 commit comments

Comments
 (0)