Reinterpret_cast after in-place new...

pull/21774/head
Vijay Pai 5 years ago
parent 1f0cdd5aad
commit a801ccbdc8
  1. 9
      include/grpcpp/impl/codegen/server_context_impl.h

@ -303,11 +303,12 @@ class ServerContextBase {
///
/// WARNING: This is experimental API and could be changed or removed.
::grpc_impl::ServerUnaryReactor* DefaultReactor() {
Reactor* reactor = reinterpret_cast<Reactor*>(&default_reactor_);
// Short-circuit the case where a default reactor was already set up by
// the TestPeer.
if (test_unary_ != nullptr) {
return reactor;
return reinterpret_cast<Reactor*>(&default_reactor_);
}
new (reactor) Reactor;
new (&default_reactor_) Reactor;
#ifndef NDEBUG
bool old = false;
assert(default_reactor_used_.compare_exchange_strong(
@ -315,7 +316,7 @@ class ServerContextBase {
#else
default_reactor_used_.store(true, std::memory_order_relaxed);
#endif
return reactor;
return reinterpret_cast<Reactor*>(&default_reactor_);
}
/// Constructors for use by derived classes

Loading…
Cancel
Save