summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/test/flatten.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-11-22 10:02:08 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-11-22 11:54:04 +0100
commit04bb9549e0a0ee567f3bd48a7707286c5abd631a (patch)
treec36c075d777c5c5359a7c7d1f14849fb713c8258 /compilerplugins/clang/test/flatten.cxx
parentede08b49c6336b220ef6e07f65935512537f7dc8 (diff)
loplugin:flatten look for large if statement at end of function
the rewriter is capable of flattening the function by returning early, and inverting simple conditions. More complex conditions are just wrapped in "!(x)" Change-Id: I028fd7b018dc7347c1b323b2a73ab99c18508faa Reviewed-on: https://gerrit.libreoffice.org/45071 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/test/flatten.cxx')
-rw-r--r--compilerplugins/clang/test/flatten.cxx49
1 files changed, 49 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/flatten.cxx b/compilerplugins/clang/test/flatten.cxx
index 30f5c8f41bd9..300067b9bfa1 100644
--- a/compilerplugins/clang/test/flatten.cxx
+++ b/compilerplugins/clang/test/flatten.cxx
@@ -139,4 +139,53 @@ void top8() {
}
}
+void top9() {
+ if (foo() == 1) { // expected-error {{large if statement at end of function, rather invert the condition and exit early, and flatten the function [loplugin:flatten]}}
+ Class aClass1;
+ (void)aClass1;
+ Class aClass2;
+ (void)aClass2;
+ Class aClass3;
+ (void)aClass3;
+ Class aClass4;
+ (void)aClass4;
+ Class aClass5;
+ (void)aClass5;
+ Class aClass6;
+ (void)aClass6;
+ }
+}
+
+void top10() {
+ // no warning expected
+ if (foo() == 2) {
+ if (foo() == 1) {
+ Class aClass1;
+ (void)aClass1;
+ Class aClass2;
+ (void)aClass2;
+ Class aClass3;
+ (void)aClass3;
+ }
+ }
+}
+
+int top11() {
+ // no warning expected
+ if (foo() == 1) {
+ Class aClass1;
+ (void)aClass1;
+ Class aClass2;
+ (void)aClass2;
+ Class aClass3;
+ (void)aClass3;
+ Class aClass4;
+ (void)aClass4;
+ Class aClass5;
+ (void)aClass5;
+ Class aClass6;
+ (void)aClass6;
+ }
+ return 1;
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */