chenBright opened a new pull request, #3547:
URL: https://github.com/apache/brpc/pull/3547

   ### What problem does this PR solve?
   
   Issue Number: resolve #3546
   
   Problem Summary:
   
   `std::enable_if<cond>` is a class type whatever `cond` is, only 
`std::enable_if<cond>::type` 
   goes away when the condition fails. Three places write the former, so their 
constraints check 
   nothing.
   
   -  `bvar/reducer.h`: the babylon backed partial specializations of 
`Adder`/`Maxer`/`Miner` are 
       keyed on `std::enable_if<cond>` while `Adder<T>` means `Adder<T, void>`, 
so they never 
       match and the babylon counters  are dead code even when built with 
       `--define with_babylon_counter=true`. Adding the missing `::type` is not 
enough: babylon 
       constrains its counters with a `static_assert` in the class body, so 
probing them with 
       `std::is_constructible` is a hard error instead of a substitution 
failure, and the specializations 
       then expose three latent defects. `Adder::reset()` hits an inverted 
`CHECK` and never resets, 
       `Maxer`/`Miner` return 0 instead of the identity of their operator for 
an empty sampling period, 
       and `get_value()` carries no `CHECK` so `Window<Maxer<> >` loses its 
warning.
   -  `butil/memory/scope_guard.h`: the default argument of the primary 
template and the argument 
       list of the partial specialization share the same wrong expression, so 
they always agree and a 
       callback returning non void is silently accepted.
   -  `butil/containers/optional.h`: the in place constructor is constrained by 
`std::enable_if<cond>*`, 
       a valid pointer type whatever `cond` is, so `optional<int>` is reported 
constructible from a string 
       literal. The `initializer_list` in place constructor puts its 
constrained parameter after a parameter 
       pack without a default argument, so it can neither be deduced nor 
specified and is never viable.
   
   ### What is changed and the side effects?
   
   Changed:
   
   `bvar/reducer.h`
   - Key the babylon backed specializations on `typename 
std::enable_if<cond>::type`.
   - Replace the `std::is_constructible` probe with 
`IsBabylonCounterSupported`, a two step trait 
      mirroring the constraint of babylon counters. It cannot be one expression 
because `sizeof` does 
      not apply to void or to an incomplete type.
   
   `butil/memory/scope_guard.h`
   - Resolve the constraint to `void` and specialize on `ScopeGuard<Callback, 
void>`.
   
   `butil/containers/optional.h`
   - Constrain both in place constructors with `typename std::enable_if<cond, 
bool>::type = false`, 
      the form already used elsewhere in the file.
   
   Side effects:
   - Performance effects:
   
   - Breaking backward compatibility: 
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   


-- 
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