If `true`, struct left brace will be placed after line breaks.
true:
struct new_struct struct_name =
{...};
false:
struct new_struct struct_name = {
...};
Differential D91949
[clang-format] Add BeforeStructInitialization option in BraceWrapping configuration anastasiia_lukianenko on Nov 23 2020, 2:02 AM. Authored by
Details If `true`, struct left brace will be placed after line breaks. false:
Diff Detail Event TimelineComment Actions Could you make you patch with a full context diff, plus we really want unit tests for all changes if you change Format.h you need to regenerate the ClangFormatStyleOptions.rst by running dump_style.py in clang/docs/tools Comment Actions
Comment Actions Ok, thank you for making the changes so its easier to review, Do you think this style should be part of the "BraceMapping" style? Comment Actions Firstly thank you for the patch, and believe me I don't want to discourage you (as I remember my first patches), I think the rational is ok, but I think you might be laser focused on your use case and not looking at the impact on the change of the wider clang-format. To be honest I can't really tell without checking it out and building it but certainly I think its missing some initialization which perhaps might mean its not actually doing anything, (perhaps in debug mode it is) but in release mode it could end up making random changes if it gets initialized incorrectly. I think it "does what it says on the tin", but I think it could have some other consequences and side effects which we need to explore first, these are best exposed by adding some more tests to show other areas where the same pattern of tokens occurs do not change by the setting of this configuration option
Comment Actions Thanks for the detailed review. After more detailed testing, I will upload a new version of the patches, which will fix configuration influence on other formatting options.
Comment Actions
Comment Actions Its close
Comment Actions Also how does this relate to the AfterStruct setting? bool AfterStruct Wrap struct definitions. true: struct foo { int x; }; false: struct foo { int x; }; I presume this only applied to definition and not instantiation Comment Actions AfterStruct setting doesn't affect struct initialization. Your presumption is right. struct new_struct struct_name = { a = 1 }; struct new_struct struct_name = { a = 1 }; struct new_struct struct_name = { a = 1, }; There is a test which shows that first example is not expected in case without break after '=' TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { // Elaborate type variable declarations. verifyFormat("struct foo a = {bar};\nint n;"); Comment Actions I think the revision whilst it does what is needed to structs doesn't address the many other times this forms appear. I think we need something a little more extensive. It can't just be when a line starts with struct |