virtual_bodies.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef VIRTUAL_METHODS_H_
  5. #define VIRTUAL_METHODS_H_
  6. // Note: This is not actual windows.h but the stub file in system/windows.h
  7. #include <windows.h>
  8. #define CR_BEGIN_MSG_MAP_EX(theClass) virtual int f() { return 4; }
  9. #define BEGIN_SAFE_MSG_MAP_EX(theClass) virtual int g() { return 4; }
  10. // Should warn about virtual method usage.
  11. class VirtualMethodsInHeaders {
  12. public:
  13. // Don't complain about these.
  14. virtual void MethodIsAbstract() = 0;
  15. virtual void MethodHasNoArguments();
  16. virtual void MethodHasEmptyDefaultImpl() {}
  17. // But complain about this:
  18. virtual bool ComplainAboutThis() { return true; }
  19. SYSTEM_INLINE_VIRTUAL
  20. CR_BEGIN_MSG_MAP_EX(Sub)
  21. BEGIN_SAFE_MSG_MAP_EX(Sub)
  22. };
  23. // Complain on missing 'virtual' keyword in overrides.
  24. class WarnOnMissingVirtual : public VirtualMethodsInHeaders {
  25. public:
  26. void MethodHasNoArguments() override;
  27. };
  28. // Don't complain about things in a 'testing' namespace.
  29. namespace testing {
  30. struct TestStruct {};
  31. } // namespace testing
  32. class VirtualMethodsInHeadersTesting : public VirtualMethodsInHeaders {
  33. public:
  34. // Don't complain about no virtual testing methods.
  35. void MethodHasNoArguments();
  36. private:
  37. testing::TestStruct tester_;
  38. };
  39. #endif // VIRTUAL_METHODS_H_