inline_ctor.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright (c) 2012 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 INLINE_CTOR_H_
  5. #define INLINE_CTOR_H_
  6. #include <string>
  7. #include <vector>
  8. class InlineCtorsArentOKInHeader {
  9. public:
  10. InlineCtorsArentOKInHeader() {}
  11. ~InlineCtorsArentOKInHeader() {}
  12. private:
  13. std::vector<int> one_;
  14. std::vector<std::string> two_;
  15. };
  16. #define INLINE_CTORS_IN_A_MACRO(CLASS_NAME) \
  17. class CLASS_NAME { \
  18. public: \
  19. CLASS_NAME() {} \
  20. ~CLASS_NAME() {} \
  21. \
  22. private: \
  23. std::vector<int> one_; \
  24. std::vector<std::string> two_; \
  25. }
  26. INLINE_CTORS_IN_A_MACRO(InlineCtorsBehindAMacroArentOKInHeader);
  27. MACRO_FROM_CPP;
  28. class DeletedMembersInHeaderAreOKThough {
  29. public:
  30. DeletedMembersInHeaderAreOKThough() = delete;
  31. ~DeletedMembersInHeaderAreOKThough() = delete;
  32. DeletedMembersInHeaderAreOKThough(const DeletedMembersInHeaderAreOKThough&) =
  33. delete;
  34. private:
  35. std::vector<int> one_;
  36. std::vector<std::string> two_;
  37. };
  38. class ExplicitlyInlinedIsAlsoOK {
  39. ExplicitlyInlinedIsAlsoOK();
  40. ~ExplicitlyInlinedIsAlsoOK();
  41. ExplicitlyInlinedIsAlsoOK(const ExplicitlyInlinedIsAlsoOK&);
  42. private:
  43. std::vector<int> one_;
  44. std::vector<std::string> two_;
  45. };
  46. inline ExplicitlyInlinedIsAlsoOK::ExplicitlyInlinedIsAlsoOK() {
  47. }
  48. inline ExplicitlyInlinedIsAlsoOK::~ExplicitlyInlinedIsAlsoOK() {
  49. }
  50. inline ExplicitlyInlinedIsAlsoOK::ExplicitlyInlinedIsAlsoOK(
  51. const ExplicitlyInlinedIsAlsoOK&) {
  52. }
  53. struct TrivialStruct {
  54. int something_;
  55. };
  56. struct NonTrivialStruct {
  57. NonTrivialStruct();
  58. ~NonTrivialStruct();
  59. int something_;
  60. };
  61. // Plugin doesn't warn about inlining trivial member dtor calls.
  62. struct FourTrivialMembers {
  63. ~FourTrivialMembers();
  64. TrivialStruct a;
  65. TrivialStruct b;
  66. TrivialStruct c;
  67. TrivialStruct d;
  68. };
  69. // Plugin doesn't warn about inlining three ctor/dtor calls.
  70. struct ThreeNonTrivialMembers {
  71. NonTrivialStruct a;
  72. NonTrivialStruct b;
  73. NonTrivialStruct c;
  74. };
  75. // Plugin does warn about inlining four ctor/dtor calls.
  76. struct FourNonTrivialMembers {
  77. NonTrivialStruct a;
  78. NonTrivialStruct b;
  79. NonTrivialStruct c;
  80. NonTrivialStruct d;
  81. };
  82. #endif // INLINE_CTOR_H_