clang-format issues

Sysprogs forums Forums VisualGDB clang-format issues

This topic contains 4 replies, has 2 voices, and was last updated by  mttjcksn 1 week, 6 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #30411


    Hi there,

    I’m using VisualGDB 5.5 with Microsoft Visual Studio Community 2019 Version 16.9.3, and getting unpredictable results with clang-format.

    All project configurations are set to Default Clang for both intellisense and code formatting. I have specified a .clang-format file that works with LLVM clang-format v12 on the command line, but I get all sorts of issues with it in visual studio.

    For example, formatting this line:

    ALIGN_32BYTES(volatile uint32_t buffer[____EXAMPLE_MACRO_1 * ____EXAMPLE_MACRO_2 * ____EXAMPLE_MACRO_3] __attribute__((section(".bufferSection"))));

    using visualGDB clang-format:

    volatile uint32_t
    buffer[____EXAMPLE_MACRO_1 * ____EXAMPLE_MACRO_2 * ____EXAMPLE_MACRO_3]

    but using llvm clang-format v12:

    ALIGN_32BYTES(volatile uint32_t buffer[____EXAMPLE_MACRO_1 * ____EXAMPLE_MACRO_2 * ____EXAMPLE_MACRO_3] __attribute__((section(".bufferSection"))));

    Here is an example clang-format file that gives this result:

    <hr />

    Language: Cpp
    # BasedOnStyle: Microsoft
    AccessModifierOffset: -2
    AlignAfterOpenBracket: Align
    AlignConsecutiveMacros: true
    AlignConsecutiveAssignments: true
    AlignConsecutiveDeclarations: false
    AlignEscapedNewlines: Right
    AlignOperands: true
    AlignTrailingComments: true
    # AllowAllArgumentsOnNextLine: true
    # AllowAllConstructorInitializersOnNextLine: true
    AllowAllParametersOfDeclarationOnNextLine: true
    # AllowShortBlocksOnASingleLine: Never
    # AllowShortCaseLabelsOnASingleLine: false
    # AllowShortFunctionsOnASingleLine: None
    # AllowShortLambdasOnASingleLine: All
    # AllowShortIfStatementsOnASingleLine: Never
    # AllowShortLoopsOnASingleLine: false
    AlwaysBreakAfterDefinitionReturnType: None
    AlwaysBreakAfterReturnType: None
    AlwaysBreakBeforeMultilineStrings: false
    AlwaysBreakTemplateDeclarations: MultiLine
    BinPackArguments: true
    BinPackParameters: true
    # AfterCaseLabel: false
    AfterClass: true
    AfterControlStatement: true
    AfterEnum: true
    AfterFunction: true
    AfterNamespace: true
    AfterObjCDeclaration: true
    AfterStruct: true
    AfterUnion: false
    AfterExternBlock: true
    BeforeCatch: true
    BeforeElse: true
    IndentBraces: false
    SplitEmptyFunction: true
    SplitEmptyRecord: true
    SplitEmptyNamespace: true
    BreakBeforeBinaryOperators: None
    BreakBeforeBraces: Allman
    ColumnLimit: '0'


    In this specific example it looks as if the visualGDB clang-format is ignoring  ColumnLimit: '0'.  There are various other differences between the outputs, such as how array initialisers are formatted, and where line breaks are placed in expressions.

    I would ideally use the visualGDB clang format, because I have issues with the visual studio intellisense when using visualGDB, but so far have not been able to make a usable .clang-format file that gives the same results in llvm clang-format and visualGDB clang-format.

    Any ideas??

    Many thanks, Matt





    The VisualGDB’s IntelliSense engine internally uses Clang 6.0. Hence if you are relying on a setting that was added in a newer version, it will not work. We will update the Clang version used by our engine in one of the next VisualGDB releases.



    Thanks for the reply. I just checked every setting in the example I gave above against the version 6 docs here:

    The only one not present was AlignConsecutiveMacros, so I removed it.  Unfortunately the outcome is still the same.  I have double checked that the file is using this clang-format file by clicking the formatting style button in the editor.

    Is there anything else I am missing?

    Is there a list of clang version differences, or any kind of tool to help me work out what the differences are so I can convert a modern clang format to use the old version 6 format?

    Is it possible to disable VisualGDB’s clang-format but keep VisualGDB’s intellisense?

    Many thanks

    • This reply was modified 1 week, 6 days ago by  mttjcksn.


    No problem, we can walk you through the various settings and try to suggest a few workarounds, however we would kindly ask you renew your technical support first, as it has expired a while ago.



    Thanks.  I have had  some luck using BasedOnStyle: LLVM and adding a small number of rules on top of that. Perhaps having a large clang-format file causes more problems than it’s worth!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.