llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.25k stars 12.08k forks source link

clang-format formats lines exceeding `ColumnLimit`. #116179

Open LinZhihao-723 opened 1 week ago

LinZhihao-723 commented 1 week ago

When running clang-format on the following code section:

    RegexASTCapture(
            std::unique_ptr<RegexAST<NFAStateType>> group_regex_ast,
            std::unique_ptr<Tag> tag
    )
            : m_group_regex_ast{
                      nullptr == group_regex_ast
                              ? throw std::invalid_argument("Group regex AST cannot be null")
                              : std::move(group_regex_ast)},
              m_tag{nullptr == tag ? throw std::invalid_argument("Tag cannot be null")
                                   : std::move(tag)} {
        RegexAST<NFAStateType>::set_subtree_positive_tags(
                m_group_regex_ast->get_subtree_positive_tags()
        );
        RegexAST<NFAStateType>::add_subtree_positive_tags({m_tag.get()});
    }

The formatted result is:

    RegexASTCapture(
            std::unique_ptr<RegexAST<NFAStateType>> group_regex_ast,
            std::unique_ptr<Tag> tag
    )
            : m_group_regex_ast{nullptr == group_regex_ast ? throw std::invalid_argument("Group regex AST cannot be null") : std::move(group_regex_ast)},
              m_tag{nullptr == tag ? throw std::invalid_argument("Tag cannot be null")
                                   : std::move(tag)} {
        RegexAST<NFAStateType>::set_subtree_positive_tags(
                m_group_regex_ast->get_subtree_positive_tags()
        );
        RegexAST<NFAStateType>::add_subtree_positive_tags({m_tag.get()});
    }

Configure files we used: https://github.com/y-scope/yscope-dev-utils/commit/0ae873bcda1b71bd8aaadc77142fb664974b22ab The ColumnLimit is set to 100, but exceeded The bug can be reproduced on both clang-format 18.1 and 19.1

llvmbot commented 1 day ago

@llvm/issue-subscribers-bug

Author: Lin Zhihao (LinZhihao-723)

When running clang-format on the following code section: ``` RegexASTCapture( std::unique_ptr<RegexAST<NFAStateType>> group_regex_ast, std::unique_ptr<Tag> tag ) : m_group_regex_ast{ nullptr == group_regex_ast ? throw std::invalid_argument("Group regex AST cannot be null") : std::move(group_regex_ast)}, m_tag{nullptr == tag ? throw std::invalid_argument("Tag cannot be null") : std::move(tag)} { RegexAST<NFAStateType>::set_subtree_positive_tags( m_group_regex_ast->get_subtree_positive_tags() ); RegexAST<NFAStateType>::add_subtree_positive_tags({m_tag.get()}); } ``` The formatted result is: ``` RegexASTCapture( std::unique_ptr<RegexAST<NFAStateType>> group_regex_ast, std::unique_ptr<Tag> tag ) : m_group_regex_ast{nullptr == group_regex_ast ? throw std::invalid_argument("Group regex AST cannot be null") : std::move(group_regex_ast)}, m_tag{nullptr == tag ? throw std::invalid_argument("Tag cannot be null") : std::move(tag)} { RegexAST<NFAStateType>::set_subtree_positive_tags( m_group_regex_ast->get_subtree_positive_tags() ); RegexAST<NFAStateType>::add_subtree_positive_tags({m_tag.get()}); } ``` Configure files we used: https://github.com/y-scope/yscope-dev-utils/commit/0ae873bcda1b71bd8aaadc77142fb664974b22ab The `ColumnLimit` is set to 100, but exceeded The bug can be reproduced on both clang-format 18.1 and 19.1