This is an archive of the discontinued LLVM Phabricator instance.

[clang][DeclPrinter] Fix AST print of curly constructor initializers
ClosedPublic

Authored by strimo378 on Jul 26 2023, 3:23 AM.

Details

Summary

DeclPrinter::PrintConstructorInitializers did not consider curly constructor initializers. Any curly constructor initializers (e.g. A() : Field{}) was printed with round brackets (e.g. A() : Field({})).

https://github.com/llvm/llvm-project/issues/64061

Diff Detail

Event Timeline

strimo378 created this revision.Jul 26 2023, 3:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 3:23 AM
strimo378 requested review of this revision.Jul 26 2023, 3:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2023, 3:23 AM
strimo378 edited the summary of this revision. (Show Details)Jul 26 2023, 3:31 AM
strimo378 added a reviewer: aaron.ballman.
strimo378 edited the summary of this revision. (Show Details)Jul 26 2023, 3:37 AM
shafik added a subscriber: shafik.Jul 26 2023, 11:20 AM

Maybe add a designated init test in there as well e.g.

struct A {
    int x {};
};
struct B {
    B() : a({.x = 1}) {
    }
    A a;
};
aaron.ballman added inline comments.Jul 26 2023, 11:28 AM
clang/test/AST/ast-print-method-decl.cpp
104

Can you add another ctor that uses round parens for the member initializers?

strimo378 updated this revision to Diff 544566.EditedJul 26 2023, 5:56 PM

@aaron.ballman and @shafik: Thank you for your fast review and your suggestions. I have added additional ctor variants accordingly.

This revision is now accepted and ready to land.Jul 27 2023, 5:16 AM
This revision was landed with ongoing or failed builds.Jul 27 2023, 8:44 AM
This revision was automatically updated to reflect the committed changes.