Menu ▾ ▴

#611 Unexpected formatting of comment

open
nobody
None
5 days ago
2026-11-04
Zenju
No

Astyle 3.6.21 is almost perfect, just one tiny regression compared to 3.6.20:

Input for Astyle 3.6.21, but the comment should remain unchanged:

int get()
{
#ifdef ZEN_WIN
    return 1;

#else
    /* test

    #include <blkid/blkid.h> */
    return 0;
#endif
}

Unexpected result:

int get()
{
#ifdef ZEN_WIN
    return 1;

#else
    /* test

#include <blkid/blkid.h> */
    return 0;
#endif
}

Thx for your stellar work on Astyle! Wouldn't enjoy programming that much if I had to use clang-format.

Best, Zenju

Discussion

  • Zenju

    Zenju - 2026-11-04

    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
    
     
  • André Simon

    André Simon - 2026-11-05

    Please test with 3.6.22.

     
  • Zenju

    Zenju - 2026-11-06

    The following example doesn't work in 3.6.22:

    Input:

    int get()
    {
        /* test
    
    #include <blkid/blkid.h> */
        return 0;
    }
    

    Output (unexpectedly indents before #include)

    int get()
    {
        /* test
    
        #include <blkid/blkid.h> */
        return 0;
    }
    
     
  • Zenju

    Zenju - 2026-11-06

    Probably related, the following comment is also partially indented:

    Input:

    std::string test[] =
    {
        { /* test
                       abc */
            "test"
        }
    };
    

    Output => two spaces were inserted before "abc"

    std::string test[] =
    {
        { /* test
                         abc */
            "test"
        }
    };
    
     
  • Zenju

    Zenju - 2026-11-06

    Here's a different example. Its admittedly weird, but it's OpenSSL code, and formatting is causing havok on the code: (didn't happen with previous 3.6.21):

    Input:

    #define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used  \
    
    * interface */
    #define ENGINE_CTRL_LOAD_CONFIGURATION 6 /* Load a configuration,  \
    * or so */
    
    /*
    
     * These control commands allow an application to deal with an arbitrary
     */
    

    Output (unexpected indent before "These control")

    #define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used  \
    
    * interface */
    #define ENGINE_CTRL_LOAD_CONFIGURATION 6 /* Load a configuration,  \
    * or so */
    
        /*
    
         * These control commands allow an application to deal with an arbitrary
         */
    
     

    Last edit: Zenju 2026-11-06
  • André Simon

    André Simon - 5 days ago

    Please test with 3.6.23. First two were old bugs, last one a real regression.

     
  • Zenju

    Zenju - 5 days ago

    Awesome, this fixes 99% of issues!

    One remaining issue with 3.6.23. The following example remains unchanged after format:
    Apparently it makes a difference if the block is at the beginning of the file or not:

    #if  defined TEST
    /* test
    
    * test */
    #define TEST
    #endif
    
    #if  defined TEST
        /* test
    
        * test */
        #define TEST
    #endif
    
     
  • Zenju

    Zenju - 5 days ago

    Also the following issue with 3.6.23:

    Input:

    void test()
    {
        {
            switch (opcode)
            { 
                case 1:
                {
                    {
                        {
                            /* test
                            ** test */
                            assert(true);  /* test
                             ** abc */
                            cnt = 0;
                        }
                    }
                }
            }
        }
    }
    

    Output: (the "** abc" line is shifted to the left and not aligned with the previous "assert")

    void test()
    {
        {
            switch (opcode)
            {
                case 1:
                {
                    {
                        {
                            /* test
                            ** test */
                            assert(true);  /* test
                     ** abc */
                            cnt = 0;
                        }
                    }
                }
            }
        }
    }
    
     

Log in to post a comment.