This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] PR35514 brace-init member initializers in function-try-blocks are not formatted correctly
ClosedPublic

Authored by MyDeveloperDay on Dec 15 2020, 6:31 AM.

Details

Summary

https://bugs.llvm.org/show_bug.cgi?id=35514

Initializer lists with a try-block are incorrectly formatted.

e.g.

Foo(int abc, int def) try : _abc(abc), _def{def}, _ghi{1} {
  callA();
  callB();
} catch (std::exception&) {
}

is formatted as:

Foo(int abc, int def) try : _abc(abc), _def { def }
, _ghi{1} {
  callA();
  callB();
}
catch (std::exception&) {
}

This revision adds support in the parseTryCatch for braced initializers in the initializer list

Diff Detail

Event Timeline

MyDeveloperDay requested review of this revision.Dec 15 2020, 6:31 AM
MyDeveloperDay created this revision.
HazardyKnusperkeks accepted this revision.
This revision is now accepted and ready to land.Dec 15 2020, 11:47 AM
curdeius accepted this revision.Dec 16 2020, 1:53 AM

I'd like to see a test with braces inside the try (intoducing scope), just to verify it doesn't break.

E.g.:

verifyFormat("class A {\n"
             "  int a;\n"
             "  A() try : a(0), b{1}, c{2} {\n"
             "    { // New scope.\n"
             "    }\n"
             "  } catch (...) {\n"
             "    throw;\n"
             "  }\n"
             "};\n");

Otherwise LGTM.

I'd like to see a test with braces inside the try (intoducing scope), just to verify it doesn't break.

Sure let me add that.

Add additional unit test