1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-23 11:15:13 +03:00
aports/community/uncrustify/use-default-only-with-a-switch.patch
Kevin Daudt ceb32ba69a community/uncrustify: localize patch
Patches from github are volatile, the index hashes changed.
2021-05-24 18:57:50 +00:00

89 lines
3.4 KiB
Diff

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;