This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Don't generate incorrect fixes for class constructed from list-initialized arguments
ClosedPublic

Authored by hokein on Nov 19 2018, 8:36 AM.

Details

Summary

Currently the smart_ptr check (modernize-make-unique) generates the
fixes that cannot compile for cases like below -- because brace list can
not be deduced in make_unique.

struct Bar { int a, b; };
struct Foo { Foo(Bar); };
auto foo = std::unique_ptr<Foo>(new Foo({1, 2}));

Diff Detail

Repository
rL LLVM

Event Timeline

hokein created this revision.Nov 19 2018, 8:36 AM
aaron.ballman accepted this revision.Nov 20 2018, 6:40 AM

Currently the smart_ptr check (modernize-make-unique) generates the fixes that cannot compile for cases like below -- because brace list can not be deduced in make_unique.

class Bar { int a, b; };
class Foo { Foo(Bar); };
auto foo = std::unique_ptr<Foo>(new Foo({1, 2}));

This code isn't legal in the first place. ;-)

Aside from some small nits, this LGTM.

clang-tidy/modernize/MakeSmartPtrCheck.cpp
287 ↗(On Diff #174623)

I assume this is expected to be false? Foo{1}

294 ↗(On Diff #174623)

No need for this lambda (then again, it was in the original code).

295 ↗(On Diff #174623)

No need to assert this; dyn_cast<> does it for you.

This revision is now accepted and ready to land.Nov 20 2018, 6:40 AM
hokein updated this revision to Diff 174771.Nov 20 2018, 7:46 AM
hokein marked 2 inline comments as done.

address comments.

Currently the smart_ptr check (modernize-make-unique) generates the fixes that cannot compile for cases like below -- because brace list can not be deduced in make_unique.

class Bar { int a, b; };
class Foo { Foo(Bar); };
auto foo = std::unique_ptr<Foo>(new Foo({1, 2}));

This code isn't legal in the first place. ;-)

Thanks for the review. Fixed :)

clang-tidy/modernize/MakeSmartPtrCheck.cpp
287 ↗(On Diff #174623)

Yes, added this sample to the comment.

hokein edited the summary of this revision. (Show Details)Nov 20 2018, 7:46 AM
This revision was automatically updated to reflect the committed changes.