Skip to content

[clang-format] C# attribute on auto property lead to strange formatting #101487

@TobiasFunk

Description

@TobiasFunk

Hey when i execute clang-format.exe --verbose --style=file -i Program.cs on this code:

using System;

namespace ConsoleApp2
{
    [AttributeUsage(AttributeTargets.All)]
    public class SimpleAttribute : Attribute
    {
    }

    internal class Program
    {
        bool AutoAllowKnownApps
        {
            get; 
            [Simple]
            set;
        }

        static void Main(string[] args)
        {
        }
    }
}

i get a really strange result code

using System;

namespace ConsoleApp2
{
    [AttributeUsage(AttributeTargets.All)]
    public class SimpleAttribute : Attribute
    {
    }

    internal class Program
    {
        bool AutoAllowKnownApps
        {
        get; [Simple]
            set;
        }

            static void Main(string[] args)
            {
            }
    }
}

i found out that it is related to the attribute when removing it everything seems to format correctly.

only for completenes i use this config but it also happens with the default config

Language: CSharp
BasedOnStyle: Microsoft
Standard: c++20
UseTab: Never
IndentWidth: 4
ColumnLimit: 120
SortIncludes: CaseSensitive

AlignConsecutiveMacros: true

NamespaceIndentation: All
IndentCaseLabels: false
IndentPPDirectives: None
IndentWrappedFunctionNames: false

AllowShortFunctionsOnASingleLine: None
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false

AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false

BinPackArguments: false
BinPackParameters: false
FixNamespaceComments: false
CommentPragmas: '^(\\|\/)*\W*(<\w*|\\\w*){1}' # Don't mess around with doxygen

BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true

ConstructorInitializerAllOnOneLineOrOnePerLine: true
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
PointerAlignment: Left
KeepEmptyLinesAtTheStartOfBlocks: false
AlignAfterOpenBracket: Align
AccessModifierOffset: -4

SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
BreakAfterAttributes: Leave

BreakBeforeBraces: Custom
BraceWrapping:
  AfterNamespace: true
  AfterEnum: true
  AfterStruct: true
  AfterClass: true
  AfterUnion: true
  AfterFunction: true
  AfterExternBlock: true
  AfterCaseLabel: true
  AfterControlStatement: true
  AfterObjCDeclaration: true
  BeforeCatch: true
  BeforeLambdaBody: true
  BeforeElse: true
  BeforeWhile: true
  IndentBraces: false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions