Menu

#596 Unexpected change of raw string literal

open-fixed
None
2026-02-24
2025-03-21
Zenju
No

AStyle built from git 2025-03-21 converts this

std::string test()
{
    return R"(
test)" + R"(
test)";
}

into this:

std::string test()
{
    return R"(
           test)" + R"(
               test)";
}

But the content of the raw string literal should never be changed!

using:

--style=allman
--suffix=none
--keep-one-line-blocks
--align-pointer=type
--min-conditional-indent=0
--max-continuation-indent=80
--indent-switches
--indent-col1-comments
--indent-preproc-block
--indent-preproc-define
--pad-header
--pad-comma
--formatted
--lineend=linux
--indent-preproc-block
--convert-tabs
--preserve-ws

Discussion

  • André Simon

    André Simon - 2025-03-26
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2026-01-30

    I pushed a fix to git

     
  • Zenju

    Zenju - 2026-02-01

    The raw string literals seem to be preserved now, unfortunately there are regressions:

    For example the layout of the switch statement in the following test sample is broken (using same astyle config as above):

    std::string test()
    {
        return std::string(R"(
                <tr>
                    <td>)") +  R"(</td>
                    <td><span style="font-weight: 600;">)" + R"(</span></td>
    )";
    }
    
    
    void generateLogFileName(const ProcessSummary& summary)
    {
        const std::wstring failStatus = [&]
                                        {
                                            switch (summary.result)
    {
        case TaskResult::success: break;
        case TaskResult::warning:   return _("Warning");
            case TaskResult::error:     return _("Error");
            case TaskResult::cancelled: return _("Stopped");
        }
        return std::wstring();
                                        }();
    }
    

    Another example is the broken layout of the lambda:

    std::string test()
    {
        return std::string(R"(
                <tr>
                    <td>)") +  R"(</td>
                    <td><span style="font-weight: 600;">)" + R"(</span></td>
    )";
    }
    
    void streamToLogFile()
    {
        const std::string footer = [&]
                                   {
                                       try
        {
            return "";
        }
        catch (const FileError& e) { throw SysError(); }
                                   }();
    }
    
     
  • André Simon

    André Simon - 2026-02-03

    Hi, is it possible the bad formatting is triggered by other code before? I cannot replicate your isolated examples (not related to the last change).

     
  • Zenju

    Zenju - 2026-02-04

    The two examples above are "complete" meaning, pasting each of them into a new cpp file and formatting keeps them unchanged (with the Astyle config from above), rather than fixing the broken switch and lambda layouts.

    This was tested with your latest version from Jan 30th, freshly compiled from gitlab.

    For some reason the presence of the raw string literals is responsible for the layout corruption. When deleting them, both the lambda and switch lay out correctly.

     

    Last edit: Zenju 2026-02-04
  • André Simon

    André Simon - 2026-02-04

    It is related to the last line of the raw string having no indent. It seems to be an older bug or regression.

     
  • André Simon

    André Simon - 2026-02-11

    I have comitted another fix.

     
  • Zenju

    Zenju - 2026-02-13

    It works! :) the raw string literals are preserved, and no regressions when applying Astyle to my whole codebase. I'll be using this version onwards. Thank you!

    PS: The VS 2022 x64/Static configuration fails to build. IMHO it could be removed entirely if unmaintained, since the effect is apparently like "Release" but with "Multi-threaded (/MT)"

     
  • André Simon

    André Simon - 2026-02-24
    • status: open-accepted --> open-fixed
     
  • André Simon

    André Simon - 2026-02-24

    Released in v 3.6.14. I have also adjusted the VS2022 static project option to enable C++17.

     

Log in to post a comment.

MongoDB Logo MongoDB