AStyle 3.6.7 produces: (full repro when inside .cpp file)
std::string test()
{
return "--" + boundaryString + "\r\n"
"Content-Type: application/json; charset=UTF-8" "\r\n"
/**/ "\r\n" +
metaDataBuf + "\r\n"
"--" + boundaryString + "\r\n"
"Content-Type: application/octet-stream" "\r\n"
/**/ "\r\n";
}
The expected indentation before "return" should be:
std::string test()
{
return "--" + boundaryString + "\r\n"
"Content-Type: application/json; charset=UTF-8" "\r\n"
/**/ "\r\n" +
metaDataBuf + "\r\n"
"--" + boundaryString + "\r\n"
"Content-Type: application/octet-stream" "\r\n"
/**/ "\r\n";
}
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
Hi, until a fix is available you can avoid this by adding string concat operator (+) like this:
I don't think it's a good idea to change the actual code just to avoid incorrect formatting of the sources. Some compilers will optimize away the string concatenations, others will not, resulting in significant runtime degradation. A better way, also obvious for future reader, is to prevent formatting on portions of the code:
For details, see Disable Formatting in the Artistic Style documentation.
Last edit: w-peuker 2025-03-12