Menu

#554 Unexpected line break in opening-braces in lambda definition

closed-fixed
None
2023-09-23
2023-08-30
No

unexpected line break is added to opening-braces in lamda definition.
As previously fixed by https://sourceforge.net/p/astyle/bugs/553/, this is not occur within immediately called lambda.
But, when used break-closing-braces, this occurs again within immediately called lambda.

code:

void func()
{
    // if-else in lambda definition
    auto b = [] {
        if (true) {
            return 1;
        } else {
            return 2;
        }
    };

    // if-else in immediately called lambda
    int c = [] {
        if (true) {
            return 1;
        } else {
            return 2;
        }
    }();
}

I ran astye as follows:

$ astyle --version
Artistic Style Version 3.4.6
$ astyle --options=none --style=1tbs sample.cpp

becomes:

@@ -3,9 +3,11 @@ void func()
 {
     // if-else in lambda definition
     auto b = [] {

-        if (true) {
+        if (true)
+        {
             return 1;
-        } else {
+        } else
+        {
             return 2;
         }
     };

I ran astye as follows:

$ astyle --version
Artistic Style Version 3.4.6
$ astyle --options=none --style=1tbs --break-closing-braces sample.cpp

becomes:

@@ -3,9 +3,12 @@ void func()
 {
     // if-else in lambda definition
     auto b = [] {

-        if (true) {
+        if (true)
+        {
             return 1;
-        } else {
+        }
+        else
+        {
             return 2;
         }
     };
@@ -14,7 +17,9 @@ void func()
     int c = [] {
         if (true) {
             return 1;
-        } else {
+        }
+        else
+        {
             return 2;
         }
     }();
1 Attachments

Discussion

  • André Simon

    André Simon - 2023-09-01
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2023-09-01

    You can test a fix in the latest git commit.

     
  • André Simon

    André Simon - 2023-09-23

    Fixed in 3.4.8

     
  • André Simon

    André Simon - 2023-09-23
    • status: open-accepted --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB