Skip to content

Commit 7edd227

Browse files
committed
GCC fixes.
PiperOrigin-RevId: 453300107
1 parent 71c1034 commit 7edd227

File tree

8 files changed

+54
-58
lines changed

8 files changed

+54
-58
lines changed

base/internal/value.post.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,13 @@ class ValueHandleBase {
311311
Value* operator->() const { return std::addressof(get()); }
312312

313313
// Called by internal accessors `base_internal::IsXHandle`.
314-
constexpr bool IsManaged() const {
315-
return (vptr() & kValueHandleManaged) != 0;
316-
}
314+
bool IsManaged() const { return (vptr() & kValueHandleManaged) != 0; }
317315

318316
// Called by internal accessors `base_internal::IsXHandle`.
319-
constexpr bool IsUnmanaged() const {
320-
return (vptr() & kValueHandleUnmanaged) != 0;
321-
}
317+
bool IsUnmanaged() const { return (vptr() & kValueHandleUnmanaged) != 0; }
322318

323319
// Called by internal accessors `base_internal::IsXHandle`.
324-
constexpr bool IsInlined() const { return (vptr() & kValueHandleBits) == 0; }
320+
bool IsInlined() const { return (vptr() & kValueHandleBits) == 0; }
325321

326322
// Called by `Transient` and `Persistent` to implement the same function.
327323
template <typename T>

base/value.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ class NullValue final : public Value, public base_internal::ResourceInlined {
150150
// Note GCC does not consider a friend member as a member of a friend.
151151
ABSL_ATTRIBUTE_PURE_FUNCTION static const NullValue& Get();
152152

153+
bool Equals(const Value& other) const override;
154+
155+
void HashValue(absl::HashState state) const override;
156+
153157
private:
154158
friend class ValueFactory;
155159
template <typename T>
@@ -169,8 +173,6 @@ class NullValue final : public Value, public base_internal::ResourceInlined {
169173
// See comments for respective member functions on `Value`.
170174
void CopyTo(Value& address) const override;
171175
void MoveTo(Value& address) override;
172-
bool Equals(const Value& other) const override;
173-
void HashValue(absl::HashState state) const override;
174176
};
175177

176178
class ErrorValue final : public Value, public base_internal::ResourceInlined {

eval/public/cel_function_adapter.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ namespace internal {
1919
struct ProtoAdapterTypeCodeMatcher {
2020
template <typename T>
2121
constexpr std::optional<CelValue::Type> type_code() {
22-
return internal::TypeCodeMatcher().type_code<T>();
23-
}
24-
25-
template <>
26-
constexpr std::optional<CelValue::Type> type_code<const google::protobuf::Message*>() {
27-
return CelValue::Type::kMessage;
22+
if constexpr (std::is_same_v<T, const google::protobuf::Message*>) {
23+
return CelValue::Type::kMessage;
24+
} else {
25+
return internal::TypeCodeMatcher().type_code<T>();
26+
}
2827
}
2928
};
3029

eval/public/cel_function_adapter_impl.h

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@ namespace internal {
3535
struct TypeCodeMatcher {
3636
template <typename T>
3737
constexpr std::optional<CelValue::Type> type_code() {
38-
int index = CelValue::IndexOf<T>::value;
39-
if (index < 0) return {};
40-
CelValue::Type arg_type = static_cast<CelValue::Type>(index);
41-
if (arg_type >= CelValue::Type::kAny) {
42-
return {};
38+
if constexpr (std::is_same_v<T, CelValue>) {
39+
// A bit of a trick - to pass Any kind of value, we use generic CelValue
40+
// parameters.
41+
return CelValue::Type::kAny;
42+
} else {
43+
int index = CelValue::IndexOf<T>::value;
44+
if (index < 0) return {};
45+
CelValue::Type arg_type = static_cast<CelValue::Type>(index);
46+
if (arg_type >= CelValue::Type::kAny) {
47+
return {};
48+
}
49+
return arg_type;
4350
}
44-
return arg_type;
45-
}
46-
47-
// A bit of a trick - to pass Any kind of value, we use generic CelValue
48-
// parameters.
49-
template <>
50-
constexpr std::optional<CelValue::Type> type_code<CelValue>() {
51-
return CelValue::Type::kAny;
5251
}
5352
};
5453

@@ -82,14 +81,12 @@ struct ValueConverterBase {
8281
// Value to native uwraps a CelValue to a native type.
8382
template <typename T>
8483
bool ValueToNative(CelValue value, T* result) {
85-
return value.GetValue(result);
86-
}
87-
88-
// Specialization for CelValue (any typed)
89-
template <>
90-
bool ValueToNative(CelValue value, CelValue* result) {
91-
*result = std::move(value);
92-
return true;
84+
if constexpr (std::is_same_v<T, CelValue>) {
85+
*result = std::move(value);
86+
return true;
87+
} else {
88+
return value.GetValue(result);
89+
}
9390
}
9491

9592
// Native to value wraps a native return type to a CelValue.

eval/public/cel_number.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ constexpr double kMaxDoubleRepresentableAsInt =
4545
constexpr double kMaxDoubleRepresentableAsUint =
4646
static_cast<double>(kUint64Max - RoundingError<uint64_t>());
4747

48+
#define CEL_ABSL_VISIT_CONSTEXPR
49+
4850
namespace internal {
4951

5052
using NumberVariant = absl::variant<double, uint64_t, int64_t>;
@@ -169,15 +171,15 @@ struct IntCompareVisitor {
169171
struct CompareVisitor {
170172
explicit constexpr CompareVisitor(NumberVariant rhs) : rhs(rhs) {}
171173

172-
constexpr ComparisonResult operator()(double v) {
174+
CEL_ABSL_VISIT_CONSTEXPR ComparisonResult operator()(double v) {
173175
return absl::visit(DoubleCompareVisitor(v), rhs);
174176
}
175177

176-
constexpr ComparisonResult operator()(uint64_t v) {
178+
CEL_ABSL_VISIT_CONSTEXPR ComparisonResult operator()(uint64_t v) {
177179
return absl::visit(UintCompareVisitor(v), rhs);
178180
}
179181

180-
constexpr ComparisonResult operator()(int64_t v) {
182+
CEL_ABSL_VISIT_CONSTEXPR ComparisonResult operator()(int64_t v) {
181183
return absl::visit(IntCompareVisitor(v), rhs);
182184
}
183185
NumberVariant rhs;
@@ -233,66 +235,67 @@ class CelNumber {
233235
constexpr explicit CelNumber(uint64_t uint_value) : value_(uint_value) {}
234236

235237
// Return a double representation of the value.
236-
constexpr double AsDouble() const {
238+
CEL_ABSL_VISIT_CONSTEXPR double AsDouble() const {
237239
return absl::visit(internal::ConversionVisitor<double>(), value_);
238240
}
239241

240242
// Return signed int64_t representation for the value.
241243
// Caller must guarantee the underlying value is representatble as an
242244
// int.
243-
constexpr int64_t AsInt() const {
245+
CEL_ABSL_VISIT_CONSTEXPR int64_t AsInt() const {
244246
return absl::visit(internal::ConversionVisitor<int64_t>(), value_);
245247
}
246248

247249
// Return unsigned int64_t representation for the value.
248250
// Caller must guarantee the underlying value is representable as an
249251
// uint.
250-
constexpr uint64_t AsUint() const {
252+
CEL_ABSL_VISIT_CONSTEXPR uint64_t AsUint() const {
251253
return absl::visit(internal::ConversionVisitor<uint64_t>(), value_);
252254
}
253255

254256
// For key lookups, check if the conversion to signed int is lossless.
255-
constexpr bool LosslessConvertibleToInt() const {
257+
CEL_ABSL_VISIT_CONSTEXPR bool LosslessConvertibleToInt() const {
256258
return absl::visit(internal::LosslessConvertibleToIntVisitor(), value_);
257259
}
258260

259261
// For key lookups, check if the conversion to unsigned int is lossless.
260-
constexpr bool LosslessConvertibleToUint() const {
262+
CEL_ABSL_VISIT_CONSTEXPR bool LosslessConvertibleToUint() const {
261263
return absl::visit(internal::LosslessConvertibleToUintVisitor(), value_);
262264
}
263265

264-
constexpr bool operator<(CelNumber other) const {
266+
CEL_ABSL_VISIT_CONSTEXPR bool operator<(CelNumber other) const {
265267
return Compare(other) == internal::ComparisonResult::kLesser;
266268
}
267269

268-
constexpr bool operator<=(CelNumber other) const {
270+
CEL_ABSL_VISIT_CONSTEXPR bool operator<=(CelNumber other) const {
269271
internal::ComparisonResult cmp = Compare(other);
270272
return cmp != internal::ComparisonResult::kGreater &&
271273
cmp != internal::ComparisonResult::kNanInequal;
272274
}
273275

274-
constexpr bool operator>(CelNumber other) const {
276+
CEL_ABSL_VISIT_CONSTEXPR bool operator>(CelNumber other) const {
275277
return Compare(other) == internal::ComparisonResult::kGreater;
276278
}
277279

278-
constexpr bool operator>=(CelNumber other) const {
280+
CEL_ABSL_VISIT_CONSTEXPR bool operator>=(CelNumber other) const {
279281
internal::ComparisonResult cmp = Compare(other);
280282
return cmp != internal::ComparisonResult::kLesser &&
281283
cmp != internal::ComparisonResult::kNanInequal;
282284
}
283285

284-
constexpr bool operator==(CelNumber other) const {
286+
CEL_ABSL_VISIT_CONSTEXPR bool operator==(CelNumber other) const {
285287
return Compare(other) == internal::ComparisonResult::kEqual;
286288
}
287289

288-
constexpr bool operator!=(CelNumber other) const {
290+
CEL_ABSL_VISIT_CONSTEXPR bool operator!=(CelNumber other) const {
289291
return Compare(other) != internal::ComparisonResult::kEqual;
290292
}
291293

292294
private:
293295
internal::NumberVariant value_;
294296

295-
constexpr internal::ComparisonResult Compare(CelNumber other) const {
297+
CEL_ABSL_VISIT_CONSTEXPR internal::ComparisonResult Compare(
298+
CelNumber other) const {
296299
return absl::visit(internal::CompareVisitor(other.value_), value_);
297300
}
298301
};

eval/public/cel_type_registry.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ struct EnumAdderT {
5555
void AddEnum(DescriptorSet&) {}
5656

5757
template <typename EnumT>
58-
void AddEnum(EnumMap&) {}
59-
60-
template <>
61-
void AddEnum<google::protobuf::NullValue>(EnumMap& map) {
62-
map["google.protobuf.NullValue"] = {{"NULL_VALUE", 0}};
58+
void AddEnum(EnumMap& map) {
59+
if constexpr (std::is_same_v<EnumT, google::protobuf::NullValue>) {
60+
map["google.protobuf.NullValue"] = {{"NULL_VALUE", 0}};
61+
}
6362
}
6463
};
6564

eval/public/cel_value.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ class CelValue {
116116
// absl::variant.
117117
using NullType = absl::monostate;
118118

119-
using MessageWrapper = MessageWrapper;
119+
// GCC: fully qualified to avoid change of meaning error.
120+
using MessageWrapper = google::api::expr::runtime::MessageWrapper;
120121

121122
private:
122123
// CelError MUST BE the last in the declaration - it is a ceiling for Type

eval/public/cel_value_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ struct MessageVisitAdapter {
9494
return op(arg);
9595
}
9696

97-
template <>
9897
T operator()(const MessageWrapper& wrapper) {
9998
ABSL_ASSERT(wrapper.HasFullProto());
10099
return op(cel::internal::down_cast<const google::protobuf::Message*>(

0 commit comments

Comments
 (0)