Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: tools/clang/plugins/tests/virtual_bodies.h

Issue 1493813003: Convert the no-inline-virtuals rule into a constructors rule. Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Rebase onto https://codereview.chromium.org/1504033010 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/clang/plugins/tests/virtual_bodies.h
diff --git a/tools/clang/plugins/tests/virtual_bodies.h b/tools/clang/plugins/tests/virtual_bodies.h
index fb971c3f1e89dd0d8f7d8cced841dff0b7f4e288..3f7898540907735f603eed153df39a1e8066d536 100644
--- a/tools/clang/plugins/tests/virtual_bodies.h
+++ b/tools/clang/plugins/tests/virtual_bodies.h
@@ -8,43 +8,133 @@
// Note: This is not actual windows.h but the stub file in system/windows.h
#include <windows.h>
-#define CR_BEGIN_MSG_MAP_EX(theClass) virtual int f() { return 4; }
-#define BEGIN_SAFE_MSG_MAP_EX(theClass) virtual int g() { return 4; }
-
-// Should warn about virtual method usage.
-class VirtualMethodsInHeaders {
- public:
- // Don't complain about these.
- virtual void MethodIsAbstract() = 0;
- virtual void MethodHasNoArguments();
- virtual void MethodHasEmptyDefaultImpl() {}
-
- // But complain about this:
- virtual bool ComplainAboutThis() { return true; }
-
- SYSTEM_INLINE_VIRTUAL
- CR_BEGIN_MSG_MAP_EX(Sub)
- BEGIN_SAFE_MSG_MAP_EX(Sub)
+struct NonTrivial {
+ NonTrivial();
+ ~NonTrivial();
};
-// Complain on missing 'virtual' keyword in overrides.
-class WarnOnMissingVirtual : public VirtualMethodsInHeaders {
+// Should warn about inline constructors with too many inline virtual methods.
+class InlineVirtualMethodsInHeaders {
public:
- void MethodHasNoArguments() override;
+ // Complain about the inline/missing constructor.
+ virtual void Method1() {}
+ virtual bool Method2() { return true; }
+ virtual void Method3() {}
+ virtual bool Method4() { return true; }
+ virtual void Method5() {}
};
-// Don't complain about things in a 'testing' namespace.
-namespace testing {
-struct TestStruct {};
-} // namespace testing
-
-class VirtualMethodsInHeadersTesting : public VirtualMethodsInHeaders {
+// Should warn about inline constructors with long inline virtual methods.
+class LongInlineVirtualMethods {
public:
- // Don't complain about no virtual testing methods.
- void MethodHasNoArguments();
+ // Complain about the inline/missing constructor.
+ virtual int LongMethod() {
+ int x = 1;
+ int y = x * x;
+ int w = 73;
+ int u = 1;
+ for (int z = 7; z < 8; ++z) {
+ if (z > x) {
+ return x + 1;
+ } else {
+ return z - 1;
+ }
+ }
+ return 1;
+ }
+};
+
+// Should not warn if enough virtual methods are out-of-line.
dcheng 2016/03/24 17:37:25 Nit: I find this comment a bit confusing because t
+class OutoflineVirtualMethodsInHeaders {
+ public:
+ // Complain about the inline/missing constructor.
+ virtual void Method1();
+ virtual bool Method2() { return true; }
+ virtual void Method3() {}
+ virtual bool Method4() { return true; }
+ virtual void Method5() {}
+};
+
+class InlineVirtualMethodsInAbstractClass {
+ public:
+ // Accept an inline constructor for a base class.
+ virtual void Abstract() = 0;
+ virtual void Method1() {}
+ virtual bool Method2() { return true; }
+ virtual void Method3() {}
+ virtual bool Method4() { return true; }
+ virtual void Method5() {}
+};
+
+class InlineVirtualMethodsWithProtectedConstructor {
+ protected:
+ // Accept an inline constructor for a base class.
+ InlineVirtualMethodsWithProtectedConstructor() {}
+
+ public:
+ virtual void Method1() {}
+ virtual bool Method2() { return true; }
+ virtual void Method3() {}
+ virtual bool Method4() { return true; }
+ virtual void Method5() {}
+};
+
+// Complain for leaf classes even if they inherit their inline virtual methods.
+class InlineVirtualMethodsInLeafClass
+ : public InlineVirtualMethodsInAbstractClass {
+ public:
+ void Abstract() override;
+};
+
+class DtorInlineVirtualMethodsInHeaders {
+ public:
+ DtorInlineVirtualMethodsInHeaders();
+ // Complain about the inline destructor.
dcheng 2016/03/24 17:37:25 Nit: non-virtual inline
+ ~DtorInlineVirtualMethodsInHeaders() {}
+
+ virtual void Method1() {}
+ virtual bool Method2() { return true; }
+ virtual void Method3() {}
+ virtual bool Method4() { return true; }
+ virtual void Method5() {}
private:
- testing::TestStruct tester_;
+ NonTrivial non_trivial;
+};
+
+class VirtualDtorInlineVirtualMethodsInHeaders {
+ public:
+ VirtualDtorInlineVirtualMethodsInHeaders();
+ // Don't complain about the inline virtual destructor.
+ virtual ~VirtualDtorInlineVirtualMethodsInHeaders() {}
+
+ virtual void Method1() {}
+ virtual bool Method2() { return true; }
+ virtual void Method3() {}
+ virtual bool Method4() { return true; }
+ virtual void Method5() {}
+
+ private:
+ NonTrivial non_trivial;
+};
+
+// Check for a bug in which the inline destructor for the most-derived class is
+// re-counted for each base class whose destructor it overrides.
+struct Base1 {
+ virtual ~Base1();
+ virtual void Abstract() = 0;
+};
+struct Base2 : Base1 {};
+struct Base3 : Base2 {};
+struct Base4 : Base3 {};
+struct Base5 : Base4 {};
+struct Base6 : Base5 {};
+struct Base7 : Base6 {};
+struct Base8 : Base7 {};
+struct Base9 : Base8 {};
+struct Derived : Base9 {
+ ~Derived() override {}
+ void Abstract() override;
};
#endif // VIRTUAL_METHODS_H_

Powered by Google App Engine
This is Rietveld 408576698