You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removing {// asdf is sufficient to format it ok.
I expect it to be formatted like this (possibly with comment in new line, but this may be llvm style):
void foo() {
{// asdf
{ int a; }
}
{
{ int b; }
}
}
The text was updated successfully, but these errors were encountered:
It seems that clang-format erroneously treats {{int a; as a malformed initializer list. (The first brace in the repro is on a separate line only because it's followed by a single line comment.)
The problem appears to be caused by UnwrappedLineParser.
UnwrappedLineParser::tryToParseBracedList calls calculateBraceTypes to see whether a left brace starts an initializer list or a block. If the left brace starts an initializer list, parseBracedList is called to consume it.
UnwrappedLineParser::calculateBraceTypes thinks {// asdf starts an initializer list, because its matching right brace is followed by a left brace (which makes sense in a constructor, e.g. in class Foo { int mem; Foo() : mem{} {};, the {} after mem is an initializer list, but does not make sense otherwise).
UnwrappedLineParser::parseBracedList consumes the initializer list and stops at the semicolon after int a (because it was called with ContinueOnSemicolons being the default, i.e. false). It is unaware that the left brace has a matching right brace.
Extended Description
Hello.
With clang-format -10 and -11 installed from repo on ubuntu 20.11 following c++ code is obviously formatted wrong:
Removing
{// asdf
is sufficient to format it ok.I expect it to be formatted like this (possibly with comment in new line, but this may be llvm style):
The text was updated successfully, but these errors were encountered: