Menu

#589 astyle 3.6.8 (git 2025-03-14): incorrect switch indentation

open-accepted
None
2026-02-13
2025-03-14
Zenju
No

AStyle built from git 2025-03-14 code produces: (full repro when inside .cpp file)

namespace fff
{
struct LastRunStats
{
};

bool getDefaultSortDirection(ColumnTypeCfg colType)
{
    switch (colType)
    {
    case ColumnTypeCfg::name:
                return true;
    case ColumnTypeCfg::lastSync:
                return false;
    case ColumnTypeCfg::lastLog:
                return true;
    }
    return true;
}
}

The expected "switch" indentation should be:

namespace fff
{
struct LastRunStats
{
};

bool getDefaultSortDirection(ColumnTypeCfg colType)
{
    switch (colType)
    {
        case ColumnTypeCfg::name:
            return true;
        case ColumnTypeCfg::lastSync:
            return false;
        case ColumnTypeCfg::lastLog:
            return true;
    }
    return true;
}
}

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

  • Zenju

    Zenju - 2025-03-14

    This is probably the same error: (full repro when inside .cpp file)

    namespace fff
    {
    struct FileAttributes
    {
    };
    
    SyncDirection getEffectiveSyncDir(SyncOperation syncOp)
    {
        switch (syncOp)
        {
        case SO_CREATE_LEFT:
            case SO_DELETE_LEFT:
                case SO_OVERWRITE_LEFT:
                    case SO_RENAME_LEFT:
                        case SO_MOVE_LEFT_FROM:
                            case SO_MOVE_LEFT_TO:
                                        return SyncDirection::left;
    
        case SO_DO_NOTHING:
            case SO_EQUAL:
                case SO_UNRESOLVED_CONFLICT:
                            break;
        }
        return SyncDirection::none;
    }
    }
    
     
  • André Simon

    André Simon - 2025-03-16

    Please try these cases with the latest git version.

     
  • André Simon

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

    Zenju - 2025-03-17

    The issue seems to be fixed!

     
  • Zenju

    Zenju - 2025-03-17

    Alas, one problematic "switch" remains:

    struct TreeView
    {
        bool operator()(const TreeLine& lhs, const TreeLine& rhs)
        {
            switch (lhs.type)
            {
            case NodeType::root:
                        return true;
            case NodeType::folder:
                    {
                        const auto* folderL = nullptr;
                        if (!folderL)
                        return false;
    
                        return true;
                    }
    
                case NodeType::files:
                            break;
        }
        assert(false);
            return false;
        }
    };
    
     
  • Zenju

    Zenju - 2026-02-13

    Issue is fixed in the latest version from 2026-02-13! Ticket can be closed.

     

Log in to post a comment.

MongoDB Logo MongoDB