Add GRPC_ABSTRACT_BASE_CLASS

pull/13288/head
ncteisen 7 years ago
parent 0a69e1ef09
commit e66ad3b3cb
  1. 1
      build.yaml
  2. 4
      src/core/ext/transport/chttp2/transport/internal.h
  3. 28
      src/core/lib/support/abstract.h

@ -104,6 +104,7 @@ filegroups:
- include/grpc/support/useful.h
headers:
- src/core/lib/profiling/timers.h
- src/core/lib/support/abstract.h
- src/core/lib/support/arena.h
- src/core/lib/support/atomic.h
- src/core/lib/support/atomic_with_atm.h

@ -38,6 +38,7 @@
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/support/abstract.h"
#include "src/core/lib/support/manual_constructor.h"
#include "src/core/lib/transport/connectivity_state.h"
#include "src/core/lib/transport/transport_impl.h"
@ -240,12 +241,15 @@ typedef enum {
class AbstractBase {
public:
AbstractBase() {}
virtual ~AbstractBase() { gpr_log(GPR_ERROR, "base dtor"); }
virtual void foo() { gpr_log(GPR_ERROR, "base"); }
GRPC_ABSTRACT_BASE_CLASS
};
class Derived : public AbstractBase {
public:
Derived() {}
virtual ~Derived() { gpr_log(GPR_ERROR, "derived dtor"); }
void foo() override { gpr_log(GPR_ERROR, "derived"); }
};

@ -0,0 +1,28 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_LIB_SUPPORT_ABSTRACT_H
#define GRPC_CORE_LIB_SUPPORT_ABSTRACT_H
// This is needed to support abstract base classes in the c core. Since gRPC
// doesn't have a c++ runtime, it will hit a linker error on delete unless
// a we define a virtual operator delete. See this blog for more info:
// https://eli.thegreenplace.net/2015/c-deleting-destructors-and-virtual-operator-delete/
#define GRPC_ABSTRACT_BASE_CLASS static void operator delete(void *p) { abort(); }
#endif /* GRPC_CORE_LIB_SUPPORT_ABSTRACT_H */
Loading…
Cancel
Save