Issue 124057
Summary clang format: incorrect indentation of lambda inside nested function calls
Labels clang
Assignees
Reporter malytomas
    ```c++
// correct / intended
const auto engineInitListener = controlThread().initialize.listen(
	[]()
	{
		if (connectionState() == ConnectionStateEnum::None)
			setScreenMainMenu();
	},
	99999);

// wrong
const auto escKeyPressListener = engineEvents().listen(inputFilter(
														 [](input::KeyPress in)
														 {
															   if (in.key != 256) // esc
																   return false;
															   if (escCallback)
															 {
																 escCallback();
																   return true;
															   }
															 return false;
														   }),
	-1099);
```

The cause is the nested function call `inputFilter`. Without it the lambda is formatted correctly.

Note: github uses 8 spaces per tab, whereas the code uses 4 space per tab. clang-format tries to align the code with middle of `inputFilter` function.

```
# requires clang-format version 16 or later
---
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignEscapedNewlines: DontAlign
AlignOperands: DontAlign
AlignTrailingComments:
  Kind: Never
AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakTemplateDeclarations: Yes
BasedOnStyle: Microsoft
BraceWrapping:
  AfterCaseLabel: true
  AfterClass: true
 AfterControlStatement: true
  AfterEnum: true
  AfterExternBlock: true
 AfterFunction: true
  AfterNamespace: true
  AfterObjCDeclaration: true
 AfterStruct: true
  AfterUnion: true
  BeforeCatch: true
  BeforeElse: true
  BeforeLambdaBody: true
  BeforeWhile: false
  IndentBraces: false
 SplitEmptyFunction: false
  SplitEmptyNamespace: false
  SplitEmptyRecord: false
BreakBeforeBraces: Custom
ColumnLimit: 1000
Cpp11BracedListStyle: false
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: false
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 4
Language: Cpp
LineEnding: DeriveLF
NamespaceIndentation: All
QualifierAlignment: Custom
QualifierOrder: ['friend', 'static', 'inline', 'constexpr', 'const', 'volatile', 'restrict', 'type']
ReflowComments: false
RequiresClausePosition: WithPreceding
SpaceAfterTemplateKeyword: false
SpaceInEmptyBlock: false
Standard: Latest
TabWidth: 4
UseTab: AlignWithSpaces
...

```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to