aboutsummaryrefslogtreecommitdiffstats
path: root/community/uncrustify/use-default-only-with-a-switch.patch
blob: 4c592b5c1cd224aa180ca43a04a329d8be22e4ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
From dc32269e659cebaa6c3a199976fbf8cf616c7b29 Mon Sep 17 00:00:00 2001
From: Guy Maurel <guy.j@maurel.de>
Date: Sat, 15 May 2021 18:38:11 +0200
Subject: [PATCH] use default only with a switch

---
 src/brace_cleanup.cpp                   | 29 +++++++++++++++----------
 tests/cpp.test                          |  1 +
 tests/expected/cpp/30225-Issue_3176.cpp |  1 +
 tests/input/cpp/Issue_3176.cpp          |  1 +
 4 files changed, 21 insertions(+), 11 deletions(-)
 create mode 100644 tests/expected/cpp/30225-Issue_3176.cpp
 create mode 100644 tests/input/cpp/Issue_3176.cpp

diff --git a/src/brace_cleanup.cpp b/src/brace_cleanup.cpp
index 03ab68e3f8..a650cfa0c2 100644
--- a/src/brace_cleanup.cpp
+++ b/src/brace_cleanup.cpp
@@ -720,7 +720,6 @@ static void parse_cleanup(BraceState &braceState, ParseFrame &frm, chunk_t *pc)
       set_chunk_parent(pc, parent);
    }
    // Issue #2281
-   LOG_FMT(LBCSPOP, "%s(%d):\n", __func__, __LINE__);
 
    if (  chunk_is_token(pc, CT_BRACE_OPEN)
       && pc->parent_type == CT_SWITCH)
@@ -740,18 +739,26 @@ static void parse_cleanup(BraceState &braceState, ParseFrame &frm, chunk_t *pc)
    if (  chunk_is_token(pc, CT_CASE)
       || chunk_is_token(pc, CT_DEFAULT))
    {
-      LOG_FMT(LBCSPOP, "%s(%d): pc->orig_line is %zu, pc->orig_col is %zu\n",
-              __func__, __LINE__, pc->orig_line, pc->orig_col);
-      set_chunk_parent(pc, CT_SWITCH);
-      size_t idx = frm.size();
-      LOG_FMT(LBCSPOP, "%s(%d): idx is %zu\n",
-              __func__, __LINE__, idx);
-      chunk_t *saved = frm.at(idx - 2).pc;
+      chunk_t *prev = chunk_get_prev_ncnnl(pc);         // Issue #3176
 
-      if (saved != nullptr)
+      if (  chunk_is_token(pc, CT_CASE)
+         || (  chunk_is_token(pc, CT_DEFAULT)
+            && chunk_is_not_token(prev, CT_ASSIGN)))
       {
-         // set parent member
-         chunk_set_parent(pc, saved);
+         // it is a CT_DEFAULT from a switch
+         LOG_FMT(LBCSPOP, "%s(%d): pc->orig_line is %zu, pc->orig_col is %zu\n",
+                 __func__, __LINE__, pc->orig_line, pc->orig_col);
+         set_chunk_parent(pc, CT_SWITCH);
+         size_t idx = frm.size();
+         LOG_FMT(LBCSPOP, "%s(%d): idx is %zu\n",
+                 __func__, __LINE__, idx);
+         chunk_t *saved = frm.at(idx - 2).pc;
+
+         if (saved != nullptr)
+         {
+            // set parent member
+            chunk_set_parent(pc, saved);
+         }
       }
    }
 
diff --git a/tests/cpp.test b/tests/cpp.test
index 84bbaa0f96..e8d1f50cd9 100644
--- a/tests/cpp.test
+++ b/tests/cpp.test
@@ -179,6 +179,7 @@
 30222  sp_assign_default.cfg                cpp/trailing_return.cpp
 30223  sp_enum_colon.cfg                    cpp/sp_enum_colon.cpp
 30224  sp_enum_colon-r.cfg                  cpp/sp_enum_colon.cpp
+30225  empty.cfg                            cpp/Issue_3176.cpp
 
 30230  sp_type_func-r.cfg                   cpp/sp_type_func.cpp
 30231  sp_type_func-f.cfg                   cpp/sp_type_func.cpp
diff --git a/tests/expected/cpp/30225-Issue_3176.cpp b/tests/expected/cpp/30225-Issue_3176.cpp
new file mode 100644
index 0000000000..2384027d8f
--- /dev/null
+++ b/tests/expected/cpp/30225-Issue_3176.cpp
@@ -0,0 +1 @@
+SecureStorage::~SecureStorage() = default;
diff --git a/tests/input/cpp/Issue_3176.cpp b/tests/input/cpp/Issue_3176.cpp
new file mode 100644
index 0000000000..2384027d8f
--- /dev/null
+++ b/tests/input/cpp/Issue_3176.cpp
@@ -0,0 +1 @@
+SecureStorage::~SecureStorage() = default;