github-actions[bot] commented on code in PR #62433:
URL: https://github.com/apache/doris/pull/62433#discussion_r3072061964


##########
be/src/exprs/aggregate/aggregate_function.h:
##########
@@ -303,12 +303,33 @@ class IAggregateFunction {
     int version {};
 };
 
+/// Marker base for aggregate function classes that intentionally form an 
inheritance
+/// hierarchy (e.g. AggregateStateUnion -> AggregateStateMerge, or
+/// AggregateFunctionForEach -> AggregateFunctionForEachV2) and therefore 
cannot be
+/// marked 'final'. Classes that inherit this marker are exempt from the
+/// static_assert in IAggregateFunctionHelper.
+struct AggregateFunctionNonFinalBase {};
+
 /// Implement method to obtain an address of 'add' function.
 template <typename Derived>
 class IAggregateFunctionHelper : public IAggregateFunction {
 public:
     IAggregateFunctionHelper(const DataTypes& argument_types_)
-            : IAggregateFunction(argument_types_) {}
+            : IAggregateFunction(argument_types_) {
+        // The static_assert is placed in the constructor body (not at class 
scope) because
+        // at class-scope instantiation time Derived is still an incomplete 
type, whereas
+        // the constructor body is instantiated lazily when a concrete object 
is constructed,
+        // at which point Derived is fully defined.
+        //
+        // Classes that form deliberate inheritance hierarchies must inherit
+        // AggregateFunctionNonFinalBase to opt out of this check.
+        static_assert(

Review Comment:
   `IAggregateFunctionHelper` is not relying on non-virtual dispatch for 
correctness here. For example, `add_batch()` still calls `derived->add(...)`, 
and `add()` is virtual in `IAggregateFunction`, so subclasses like 
`AggregateStateMerge` and `AggregateFunctionForEachV2` already dispatch 
correctly through the base pointer. Because this PR explicitly keeps those 
hierarchies via `AggregateFunctionNonFinalBase`, the new assertion/comment is 
not actually proving the stated correctness invariant; it is only enforcing a 
best-effort devirtualization/style rule. Could we either restate this as an 
optimization hint, or tighten the design so the helper really does require 
`Derived` to be the most-derived type?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to