Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
w-m mannequin opened this issue Feb 18, 2020 · 3 comments
Closed

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

w-m mannequin opened this issue Feb 18, 2020 · 3 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior bugzilla Issues migrated from bugzilla clang-format confirmed Verified by a second party invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles

Comments

@w-m
Copy link
Mannequin

w-m mannequin commented Feb 18, 2020

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?).

@mydeveloperday
Copy link
Contributor

The crash is actually an assertion

Assertion failed: Shift >= 0, file C:\clang\llvm-project\clang\lib\Format\WhitespaceManager.cpp, line 295

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@mydeveloperday mydeveloperday added the bug Indicates an unexpected problem or unintended behavior label Dec 18, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@mkurdej mkurdej added the invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles label Feb 8, 2022
@mkurdej
Copy link
Member

mkurdej commented Feb 10, 2022

Broken between v4 and v5:

"d:\Program Files\LLVM-4.0.1\bin\clang-format.exe" -style=file test.cpp
const auto result{ []() {
  const auto something = 1;
  return 2;
} };

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

"d:\Program Files\LLVM-5.0.2\bin\clang-format.exe" -style=file test.cpp
const auto result{ []() {
  const autosomething = 1;
  return 2;
} };

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

@mkurdej mkurdej self-assigned this Feb 10, 2022
@mkurdej
Copy link
Member

mkurdej commented Feb 10, 2022

Revision URI: https://reviews.llvm.org/D119419

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior bugzilla Issues migrated from bugzilla clang-format confirmed Verified by a second party invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles
Projects
None yet
Development

No branches or pull requests

3 participants