summaryrefslogtreecommitdiff
path: root/development/uncrustify/nl_func_leave_one_liners.patch
blob: 60c43119cb295ec52414b7d30bd753e3e110019c (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
From 06822aa69bf460b5ef0363f2a0cf69ec7a426bda Mon Sep 17 00:00:00 2001
From: Guy Maurel <g.maurel@agwest.de>
Date: Fri, 29 Nov 2019 18:04:25 +0100
Subject: nl_func_leave_one_liners is now completed

Ref. #2561

diff --git a/src/newlines.cpp b/src/newlines.cpp
index a7db6181..576cd874 100644
--- a/src/newlines.cpp
+++ b/src/newlines.cpp
@@ -2782,12 +2782,30 @@ static void newline_func_def_or_call(chunk_t *start)
 
          if (tmp_next != nullptr && tmp_next->type != CT_FUNC_CLASS_DEF)
          {
-            bool   is_proto = (  tmp->parent_type == CT_FUNC_PROTO
-                              || tmp->parent_type == CT_FUNC_CLASS_PROTO);
-            iarf_e a = (is_proto) ?
-                       options::nl_func_proto_type_name() :
-                       (options::nl_func_leave_one_liners()) ?                 // Issue #1511
-                       IARF_IGNORE : options::nl_func_type_name();
+            chunk_t *closing = chunk_skip_to_match(tmp);
+            chunk_t *brace   = chunk_get_next_ncnl(closing);
+            iarf_e  a;                                           // Issue #2561
+
+            if (  tmp->parent_type == CT_FUNC_PROTO
+               || tmp->parent_type == CT_FUNC_CLASS_PROTO)
+            {
+               // proto
+               a = options::nl_func_proto_type_name();
+            }
+            else
+            {
+               // def
+
+               if (  options::nl_func_leave_one_liners()
+                  && brace->flags.test(PCF_ONE_LINER))                 // Issue #1511
+               {
+                  a = IARF_IGNORE;
+               }
+               else
+               {
+                  a = options::nl_func_type_name();
+               }
+            }
 
             if (  tmp->flags.test(PCF_IN_CLASS)
                && (options::nl_func_type_name_class() != IARF_IGNORE))
diff --git a/tests/config/Issue_2561.cfg b/tests/config/Issue_2561.cfg
new file mode 100644
index 00000000..03a40504
--- /dev/null
+++ b/tests/config/Issue_2561.cfg
@@ -0,0 +1,5 @@
+sp_func_def_paren               = force
+indent_columns                  = 3
+nl_func_leave_one_liners        = true
+nl_func_type_name               = force
+mod_add_long_function_closebrace_comment = 1
diff --git a/tests/cpp.test b/tests/cpp.test
index 77797aed..39c7e421 100644
--- a/tests/cpp.test
+++ b/tests/cpp.test
@@ -96,6 +96,7 @@
 30085  nSolve.cfg                           cpp/align_class.cpp
 30086  align_class-constr.cfg               cpp/align_class-constr.cpp
 30087  Issue_1511.cfg                       cpp/Issue_1511.cpp
+30088  Issue_2561.cfg                       cpp/Issue_2561.cpp
 
 30090  bug_488.cfg                          cpp/bug_488.cpp
 30091  bug_472.cfg                          cpp/bug_472.cpp
diff --git a/tests/expected/cpp/30088-Issue_2561.cpp b/tests/expected/cpp/30088-Issue_2561.cpp
new file mode 100644
index 00000000..aa566966
--- /dev/null
+++ b/tests/expected/cpp/30088-Issue_2561.cpp
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+int getFoo () { return foo; }
+
+int
+main (int argc, char *argv[])
+{
+   printf("hello world!\n");
+
+   return 0;
+} // main
diff --git a/tests/input/cpp/Issue_2561.cpp b/tests/input/cpp/Issue_2561.cpp
new file mode 100644
index 00000000..15232fc4
--- /dev/null
+++ b/tests/input/cpp/Issue_2561.cpp
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+int getFoo() { return foo; }
+
+int main (int argc, char *argv[])
+{
+    printf("hello world!\n");
+
+    return 0;
+}