diff --git a/.bazelrc b/.bazelrc index 9d16de1c4..694bad9e3 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,9 +1,20 @@ -build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 -build --cxxopt=-fsized-deallocation +common --enable_platform_specific_config + build --enable_bzlmod -build --copt=-Wno-deprecated-declarations build --compilation_mode=fastbuild +build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 +build:linux --cxxopt=-fsized-deallocation +build:linux --copt=-Wno-deprecated-declarations + +# you will typically need to spell out the compiler for local dev +# BAZEL_VC= +# BAZEL_VC_FULL_VERSION=14.44.3520 +build:msvc --cxxopt="-std:c++20" --cxxopt="-utf-8" --host_cxxopt="-std:c++20" +build:msvc --define=protobuf_allow_msvc=true +build:msvc --test_tag_filters=-benchmark,-notap,-notestmsvc +build:msvc --build_tag_filters=-notestmsvc + test --test_output=errors # Enable matchers in googletest diff --git a/.gitignore b/.gitignore index be3a639bb..8594eee37 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ bazel-cel-cpp clang.bazelrc user.bazelrc local_tsan.bazelrc +MODULE.bazel.lock \ No newline at end of file diff --git a/bazel/antlr.patch b/bazel/antlr.patch index eefa7c200..c1aa9080c 100644 --- a/bazel/antlr.patch +++ b/bazel/antlr.patch @@ -22,4 +22,9 @@ "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/synchronization", ], - ) \ No newline at end of file + ) + +--- VERSION ++++ /dev/null +@@ -1,1 +1,0 @@ +-4.13.2 \ No newline at end of file diff --git a/bazel/cel_proto_transitive_descriptor_set.bzl b/bazel/cel_proto_transitive_descriptor_set.bzl index 1b735fe59..4f76ccfdc 100644 --- a/bazel/cel_proto_transitive_descriptor_set.bzl +++ b/bazel/cel_proto_transitive_descriptor_set.bzl @@ -52,3 +52,4 @@ cel_proto_transitive_descriptor_set = rule( }, implementation = _cel_proto_transitive_descriptor_set, ) + diff --git a/common/BUILD b/common/BUILD index c54b7777b..7606570d8 100644 --- a/common/BUILD +++ b/common/BUILD @@ -855,6 +855,7 @@ cc_test( "@com_google_absl//absl/strings:string_view", "@com_google_protobuf//:protobuf", ], + tags = ["notestmsvc"], ) cc_library( @@ -882,6 +883,7 @@ cc_test( "@com_google_absl//absl/strings:string_view", "@com_google_protobuf//:protobuf", ], + tags = ["notestmsvc"], ) cc_library( diff --git a/common/value.cc b/common/value.cc index e6764223c..54a3fd93a 100644 --- a/common/value.cc +++ b/common/value.cc @@ -1148,12 +1148,10 @@ struct WellKnownTypesValueVisitor { Value operator()(absl::Time value) const { return TimestampValue(value); } }; -struct OwningWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor { +struct OwningWellKnownTypesValueVisitor { google::protobuf::Arena* absl_nullable arena; std::string* absl_nonnull scratch; - using WellKnownTypesValueVisitor::operator(); - Value operator()(well_known_types::BytesValue&& value) const { return absl::visit(absl::Overload( [&](absl::string_view string) -> BytesValue { @@ -1242,15 +1240,18 @@ struct OwningWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor { } return ParsedMessageValue(value.release(), arena); } + + template + Value operator()(T t) const { + return WellKnownTypesValueVisitor{}.operator()(t); + } }; -struct BorrowingWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor { +struct BorrowingWellKnownTypesValueVisitor { const google::protobuf::Message* absl_nonnull message; google::protobuf::Arena* absl_nonnull arena; std::string* absl_nonnull scratch; - using WellKnownTypesValueVisitor::operator(); - Value operator()(well_known_types::BytesValue&& value) const { return absl::visit( absl::Overload( @@ -1332,6 +1333,11 @@ struct BorrowingWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor { } return ParsedMessageValue(value.release(), arena); } + + template + Value operator()(T t) const { + return WellKnownTypesValueVisitor{}.operator()(t); + } }; } // namespace @@ -1355,7 +1361,7 @@ Value Value::FromMessage( } return absl::visit( absl::Overload( - OwningWellKnownTypesValueVisitor{.arena = arena, .scratch = &scratch}, + OwningWellKnownTypesValueVisitor{/* .arena = */ arena, /* .scratch = */ &scratch}, [&](absl::monostate) -> Value { auto* cloned = message.New(arena); cloned->CopyFrom(message); @@ -1383,7 +1389,7 @@ Value Value::FromMessage( } return absl::visit( absl::Overload( - OwningWellKnownTypesValueVisitor{.arena = arena, .scratch = &scratch}, + OwningWellKnownTypesValueVisitor{/* .arena = */ arena, /* .scratch = */ &scratch}, [&](absl::monostate) -> Value { auto* cloned = message.New(arena); cloned->GetReflection()->Swap(cloned, &message); @@ -1414,7 +1420,7 @@ Value Value::WrapMessage( return absl::visit( absl::Overload( BorrowingWellKnownTypesValueVisitor{ - .message = message, .arena = arena, .scratch = &scratch}, + /* .message = */ message, /* .arena = */ arena, /* .scratch = */ &scratch}, [&](absl::monostate) -> Value { if (message->GetArena() != arena) { auto* cloned = message->New(arena); @@ -1448,7 +1454,7 @@ Value Value::WrapMessageUnsafe( return absl::visit( absl::Overload( BorrowingWellKnownTypesValueVisitor{ - .message = message, .arena = arena, .scratch = &scratch}, + /* .message = */ message, /* .arena = */ arena, /* .scratch = */ &scratch}, [&](absl::monostate) -> Value { if (message->GetArena() != arena) { return UnsafeParsedMessageValue(message); diff --git a/common/value.h b/common/value.h index 062257961..fcd6d5df7 100644 --- a/common/value.h +++ b/common/value.h @@ -81,6 +81,14 @@ #include "google/protobuf/map_field.h" #include "google/protobuf/message.h" + +#undef CEL_DISPATCHER_CONST_INIT +#ifdef _MSC_VER > 0 +#define CEL_DISPATCHER_CONST_INIT static +#else +#define CEL_DISPATCHER_CONST_INIT ABSL_CONST_INIT +#endif // ifdef _MSC_VE + namespace cel { // `Value` is a composition type which encompasses all values supported by the diff --git a/common/values/error_value.h b/common/values/error_value.h index 3decc850f..66a9ba601 100644 --- a/common/values/error_value.h +++ b/common/values/error_value.h @@ -132,7 +132,9 @@ class ABSL_ATTRIBUTE_TRIVIAL_ABI ErrorValue final ErrorValue(google::protobuf::Arena* absl_nonnull arena, const absl::Status* absl_nonnull status) - : arena_(arena), status_{.ptr = status} {} + : arena_(arena) { + status_.ptr = status; + } void CopyConstruct(const ErrorValue& other) { arena_ = other.arena_; diff --git a/common/values/optional_value.cc b/common/values/optional_value.cc index ad0a65efb..67bb01945 100644 --- a/common/values/optional_value.cc +++ b/common/values/optional_value.cc @@ -122,18 +122,18 @@ absl::Status OptionalValueEqual( return absl::OkStatus(); } -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher empty_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -149,18 +149,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher }, }; -ABSL_CONST_INIT const OptionalValueDispatcher null_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher null_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -171,18 +171,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher null_optional_value_dispatcher = { cel::Value* absl_nonnull result) -> void { *result = NullValue(); }, }; -ABSL_CONST_INIT const OptionalValueDispatcher bool_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher bool_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -195,18 +195,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher bool_optional_value_dispatcher = { }, }; -ABSL_CONST_INIT const OptionalValueDispatcher int_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher int_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -219,18 +219,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher int_optional_value_dispatcher = { }, }; -ABSL_CONST_INIT const OptionalValueDispatcher uint_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher uint_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -243,18 +243,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher uint_optional_value_dispatcher = { }, }; -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher double_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -268,18 +268,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher }, }; -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher duration_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -293,18 +293,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher }, }; -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher timestamp_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -323,19 +323,19 @@ struct OptionalValueContent { google::protobuf::Arena* absl_nonnull arena; }; -ABSL_CONST_INIT const OptionalValueDispatcher optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent content) -> google::protobuf::Arena* absl_nullable { return content.To().arena; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { ABSL_DCHECK(arena != nullptr); @@ -350,7 +350,7 @@ ABSL_CONST_INIT const OptionalValueDispatcher optional_value_dispatcher = { return common_internal::MakeOptionalValue( &optional_value_dispatcher, OpaqueValueContent::From( - OptionalValueContent{.value = result, .arena = arena})); + OptionalValueContent{/* .value = */ result, /* .arena = */ arena})); }, }, &OptionalValueHasValue, @@ -407,7 +407,7 @@ OptionalValue OptionalValue::Of(cel::Value value, } return OptionalValue(&optional_value_dispatcher, OpaqueValueContent::From(OptionalValueContent{ - .value = result, .arena = arena})); + /*.value =*/ result, /*.arena =*/ arena})); } } } diff --git a/common/values/value_variant_test.cc b/common/values/value_variant_test.cc index 1fd3629aa..24179522e 100644 --- a/common/values/value_variant_test.cc +++ b/common/values/value_variant_test.cc @@ -20,7 +20,7 @@ namespace cel::common_internal { namespace { - +#ifndef _MSC_VER template class ValueVariantTest : public ::testing::Test {}; @@ -121,6 +121,6 @@ TYPED_TEST(ValueVariantTest, Swap) { EXPECT_TRUE(lhs.Is()); EXPECT_TRUE(rhs.Is()); } - +#endif // ifndef _MSC_VER } // namespace } // namespace cel::common_internal diff --git a/internal/BUILD b/internal/BUILD index 444cec4a1..7bfdcc8fb 100644 --- a/internal/BUILD +++ b/internal/BUILD @@ -39,6 +39,7 @@ cc_test( ":align", ":testing", ], + tags = ["notestmsvc"], ) cc_library( @@ -810,6 +811,7 @@ cc_test( "@com_google_protobuf//:timestamp_cc_proto", "@com_google_protobuf//:wrappers_cc_proto", ], + tags = ["notestmsvc"], ) cc_library( diff --git a/internal/json.cc b/internal/json.cc index 63724cd6d..3c4187897 100644 --- a/internal/json.cc +++ b/internal/json.cc @@ -864,6 +864,7 @@ class MessageToJsonState { case FieldDescriptor::TYPE_GROUP: ABSL_FALLTHROUGH_INTENDED; case FieldDescriptor::TYPE_MESSAGE: + #undef GetMessage return ToJson(reflection->GetMessage(message, field), result); case FieldDescriptor::TYPE_BYTES: BytesValueToJson( diff --git a/internal/overflow_test.cc b/internal/overflow_test.cc index 38c5fa750..d82ad2baa 100644 --- a/internal/overflow_test.cc +++ b/internal/overflow_test.cc @@ -57,11 +57,11 @@ INSTANTIATE_TEST_SUITE_P( CheckedIntMathTest, CheckedIntResultTest, ValuesIn(std::vector{ // Addition tests. - {"OneAddOne", [] { return CheckedAdd(1L, 1L); }, 2L}, - {"ZeroAddOne", [] { return CheckedAdd(0, 1L); }, 1L}, - {"ZeroAddMinusOne", [] { return CheckedAdd(0, -1L); }, -1L}, - {"OneAddZero", [] { return CheckedAdd(1L, 0); }, 1L}, - {"MinusOneAddZero", [] { return CheckedAdd(-1L, 0); }, -1L}, + {"OneAddOne", [] { return CheckedAdd(int64_t{1L}, 1L); }, 2L}, + {"ZeroAddOne", [] { return CheckedAdd(int64_t{0}, 1L); }, 1L}, + {"ZeroAddMinusOne", [] { return CheckedAdd(int64_t{0}, -1L); }, -1L}, + {"OneAddZero", [] { return CheckedAdd(1L, int64_t{0}); }, 1L}, + {"MinusOneAddZero", [] { return CheckedAdd(-1L, int64_t{0}); }, -1L}, {"OneAddIntMax", [] { return CheckedAdd(1L, std::numeric_limits::max()); }, absl::OutOfRangeError("integer overflow")}, @@ -70,12 +70,12 @@ INSTANTIATE_TEST_SUITE_P( absl::OutOfRangeError("integer overflow")}, // Subtraction tests. - {"TwoSubThree", [] { return CheckedSub(2L, 3L); }, -1L}, - {"TwoSubZero", [] { return CheckedSub(2L, 0); }, 2L}, - {"ZeroSubTwo", [] { return CheckedSub(0, 2L); }, -2L}, - {"MinusTwoSubThree", [] { return CheckedSub(-2L, 3L); }, -5L}, - {"MinusTwoSubZero", [] { return CheckedSub(-2L, 0); }, -2L}, - {"ZeroSubMinusTwo", [] { return CheckedSub(0, -2L); }, 2L}, + {"TwoSubThree", [] { return CheckedSub(int64_t{2L}, 3L); }, -1L}, + {"TwoSubZero", [] { return CheckedSub(2L, int64_t{0}); }, 2L}, + {"ZeroSubTwo", [] { return CheckedSub(int64_t{0}, 2L); }, -2L}, + {"MinusTwoSubThree", [] { return CheckedSub(int64_t{-2L}, 3L); }, -5L}, + {"MinusTwoSubZero", [] { return CheckedSub(-2L, int64_t{0}); }, -2L}, + {"ZeroSubMinusTwo", [] { return CheckedSub(int64_t{0}, -2L); }, 2L}, {"IntMinSubIntMax", [] { return CheckedSub(std::numeric_limits::max(), @@ -84,10 +84,10 @@ INSTANTIATE_TEST_SUITE_P( absl::OutOfRangeError("integer overflow")}, // Multiplication tests. - {"TwoMulThree", [] { return CheckedMul(2L, 3L); }, 6L}, - {"MinusTwoMulThree", [] { return CheckedMul(-2L, 3L); }, -6L}, - {"MinusTwoMulMinusThree", [] { return CheckedMul(-2L, -3L); }, 6L}, - {"TwoMulMinusThree", [] { return CheckedMul(2L, -3L); }, -6L}, + {"TwoMulThree", [] { return CheckedMul(2L, int64_t{3L}); }, 6L}, + {"MinusTwoMulThree", [] { return CheckedMul(-2L, int64_t{3L}); }, -6L}, + {"MinusTwoMulMinusThree", [] { return CheckedMul(int64_t{-2L}, -3L); }, 6L}, + {"TwoMulMinusThree", [] { return CheckedMul(int64_t{2L}, -3L); }, -6L}, {"TwoMulIntMax", [] { return CheckedMul(2L, std::numeric_limits::max()); }, absl::OutOfRangeError("integer overflow")}, @@ -109,22 +109,22 @@ INSTANTIATE_TEST_SUITE_P( [] { return CheckedMul(0, std::numeric_limits::max()); }, 0}, // Division cases. - {"ZeroDivOne", [] { return CheckedDiv(0, 1L); }, 0}, - {"TenDivTwo", [] { return CheckedDiv(10L, 2L); }, 5}, - {"TenDivMinusOne", [] { return CheckedDiv(10L, -1L); }, -10}, - {"MinusTenDivMinusOne", [] { return CheckedDiv(-10L, -1L); }, 10}, - {"MinusTenDivTwo", [] { return CheckedDiv(-10L, 2L); }, -5}, - {"OneDivZero", [] { return CheckedDiv(1L, 0L); }, + {"ZeroDivOne", [] { return CheckedDiv(int64_t{0}, 1L); }, 0}, + {"TenDivTwo", [] { return CheckedDiv(int64_t{10L}, 2L); }, 5}, + {"TenDivMinusOne", [] { return CheckedDiv(int64_t{10L}, -1L); }, -10}, + {"MinusTenDivMinusOne", [] { return CheckedDiv(int64_t{-10L}, -1L); }, 10}, + {"MinusTenDivTwo", [] { return CheckedDiv(int64_t{-10L}, 2L); }, -5}, + {"OneDivZero", [] { return CheckedDiv(1L, int64_t{0L}); }, absl::InvalidArgumentError("divide by zero")}, {"IntMinDivMinusOne", [] { return CheckedDiv(std::numeric_limits::lowest(), -1L); }, absl::OutOfRangeError("integer overflow")}, // Modulus cases. - {"ZeroModTwo", [] { return CheckedMod(0, 2L); }, 0}, - {"TwoModTwo", [] { return CheckedMod(2L, 2L); }, 0}, - {"ThreeModTwo", [] { return CheckedMod(3L, 2L); }, 1L}, - {"TwoModZero", [] { return CheckedMod(2L, 0); }, + {"ZeroModTwo", [] { return CheckedMod(0, int64_t{2L}); }, 0}, + {"TwoModTwo", [] { return CheckedMod(int64_t{2L}, int64_t{2L}); }, 0}, + {"ThreeModTwo", [] { return CheckedMod(3L, int64_t{2L}); }, 1L}, + {"TwoModZero", [] { return CheckedMod(int64_t{2L}, 0); }, absl::InvalidArgumentError("modulus by zero")}, {"IntMinModTwo", [] { return CheckedMod(std::numeric_limits::lowest(), 2L); }, @@ -218,37 +218,37 @@ INSTANTIATE_TEST_SUITE_P( CheckedUintMathTest, CheckedUintResultTest, ValuesIn(std::vector{ // Addition tests. - {"OneAddOne", [] { return CheckedAdd(1UL, 1UL); }, 2UL}, - {"ZeroAddOne", [] { return CheckedAdd(0, 1UL); }, 1UL}, - {"OneAddZero", [] { return CheckedAdd(1UL, 0); }, 1UL}, + {"OneAddOne", [] { return CheckedAdd(uint64_t{1UL}, 1UL); }, 2UL}, + {"ZeroAddOne", [] { return CheckedAdd(uint64_t{0}, 1UL); }, 1UL}, + {"OneAddZero", [] { return CheckedAdd(uint64_t{1UL}, 0); }, 1UL}, {"OneAddIntMax", [] { return CheckedAdd(1UL, std::numeric_limits::max()); }, absl::OutOfRangeError("unsigned integer overflow")}, // Subtraction tests. - {"OneSubOne", [] { return CheckedSub(1UL, 1UL); }, 0}, - {"ZeroSubOne", [] { return CheckedSub(0, 1UL); }, + {"OneSubOne", [] { return CheckedSub(uint64_t{1UL}, 1UL); }, 0}, + {"ZeroSubOne", [] { return CheckedSub(uint64_t{0}, 1UL); }, absl::OutOfRangeError("unsigned integer overflow")}, - {"OneSubZero", [] { return CheckedSub(1UL, 0); }, 1UL}, + {"OneSubZero", [] { return CheckedSub(uint64_t{1UL}, 0); }, 1UL}, // Multiplication tests. - {"OneMulOne", [] { return CheckedMul(1UL, 1UL); }, 1UL}, - {"ZeroMulOne", [] { return CheckedMul(0, 1UL); }, 0}, - {"OneMulZero", [] { return CheckedMul(1UL, 0); }, 0}, + {"OneMulOne", [] { return CheckedMul(uint64_t{1UL}, 1UL); }, 1UL}, + {"ZeroMulOne", [] { return CheckedMul(uint64_t{0}, 1UL); }, 0}, + {"OneMulZero", [] { return CheckedMul(uint64_t{1UL}, 0); }, 0}, {"TwoMulUintMax", [] { return CheckedMul(2UL, std::numeric_limits::max()); }, absl::OutOfRangeError("unsigned integer overflow")}, // Division tests. - {"TwoDivTwo", [] { return CheckedDiv(2UL, 2UL); }, 1UL}, - {"TwoDivFour", [] { return CheckedDiv(2UL, 4UL); }, 0}, - {"OneDivZero", [] { return CheckedDiv(1UL, 0); }, + {"TwoDivTwo", [] { return CheckedDiv(uint64_t{2UL}, 2UL); }, 1UL}, + {"TwoDivFour", [] { return CheckedDiv(uint64_t{2UL}, 4UL); }, 0}, + {"OneDivZero", [] { return CheckedDiv(uint64_t{1UL}, 0); }, absl::InvalidArgumentError("divide by zero")}, // Modulus tests. - {"TwoModTwo", [] { return CheckedMod(2UL, 2UL); }, 0}, - {"TwoModFour", [] { return CheckedMod(2UL, 4UL); }, 2UL}, - {"OneModZero", [] { return CheckedMod(1UL, 0); }, + {"TwoModTwo", [] { return CheckedMod(uint64_t{2UL}, 2UL); }, 0}, + {"TwoModFour", [] { return CheckedMod(uint64_t{2UL}, 4UL); }, 2UL}, + {"OneModZero", [] { return CheckedMod(uint64_t{1UL}, 0); }, absl::InvalidArgumentError("modulus by zero")}, // Conversion test cases for int -> uint, double -> uint. diff --git a/parser/BUILD b/parser/BUILD index 554b6ac98..35cca2032 100644 --- a/parser/BUILD +++ b/parser/BUILD @@ -30,6 +30,9 @@ cc_library( copts = [ "-fexceptions", ], + defines = [ + "ANTLR4CPP_STATIC" + ], deps = [ ":macro", ":macro_expr_factory", diff --git a/parser/parser_test.cc b/parser/parser_test.cc index 3865476ee..aee121051 100644 --- a/parser/parser_test.cc +++ b/parser/parser_test.cc @@ -1485,7 +1485,7 @@ TEST_P(ExpressionTest, Parse) { macros.push_back(cel::OptFlatMapMacro()); auto result = EnrichedParse(test_info.I, macros, "", options); if (test_info.E.empty()) { - EXPECT_THAT(result, IsOk()); + ASSERT_THAT(result, IsOk()); } else { EXPECT_THAT(result, Not(IsOk())); EXPECT_EQ(test_info.E, result.status().message());