Skip to content

Spaces between type and variable name in IIFE lambda in brace init removed by formatter #44292

@w-m

Description

@w-m
mannequin
Bugzilla Link 44947
Version 9.0
OS Linux
CC @w-m,@mydeveloperday

Extended Description

The following code

int foo {[]() {
  int bar{ 0 };
  return 0;
}()};

is formatted into

int foo{ []() {
  intbar{ 0 };
  return 0;
}() };

by clang-format-9 when using -style="{AlignConsecutiveDeclarations: true, Cpp11BracedListStyle: false}".

The resulting code no longer compiles - note the missing space between int and the variable name.

Changing either formatting option will fix the problem, it's the combination that leads to the erroneous output.

The code is also correctly formatted if the outer braces (initialization of foo) are replaced by a = assignment.

I don't have a later clang-format version than 9 installed locally, but trying this code snippet in https://zed0.co.uk/clang-format-configurator with 10.0.0+b452de0 and these two formatting options, the output suddenly gets blank (-> crash?).

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorbugzillaIssues migrated from bugzillaclang-formatconfirmedVerified by a second partyinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions