This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Handle template instantiations in modenize-use-default check
ClosedPublic

Authored by malcolm.parsons on Nov 12 2016, 1:46 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

malcolm.parsons retitled this revision from to [clang-tidy] Handle template instantiations in modenize-use-default check.
malcolm.parsons updated this object.
malcolm.parsons added a subscriber: cfe-commits.
aaron.ballman added inline comments.Nov 15 2016, 10:05 AM
test/clang-tidy/modernize-use-default.cpp
142 ↗(On Diff #77728)

Would it be better if the = default were on the inline declaration rather than the out-of-line definition? If so, that might be a reasonable FIXME to add to this test (assuming you don't feel like fixing it as part of this patch).

Also, does the = delete check suffer from the same issue?

test/clang-tidy/modernize-use-default.cpp
142 ↗(On Diff #77728)

There are valid reasons for having out-of-line definitions, even when defaulted.
The delete check only triggers if there is no definition. Template instantiation can't copy a definition that doesn't exist.

aaron.ballman accepted this revision.Nov 15 2016, 11:18 AM
aaron.ballman edited edge metadata.

LGTM!

test/clang-tidy/modernize-use-default.cpp
142 ↗(On Diff #77728)

Hmm, I suppose that is true. Thanks!

This revision is now accepted and ready to land.Nov 15 2016, 11:18 AM
test/clang-tidy/modernize-use-default.cpp
142 ↗(On Diff #77728)

Scratch that.

The = delete check doesn't create conflicting duplicate fixes, but it does have an issue.
The fixes for template instantiations are correct for the operators, but not for the constructors.
This is because the AST has the wrong source range for the template instantiation's constructors.

The template's copy constructor's source range includes the parameters:
CXXConstructorDecl 0x27bc9c0 <line:31:3, col:58> col:3 PositivePrivateTemplate<T> 'void (const PositivePrivateTemplate<T> &)'

The template instantiation's copy constructor's source range does not:
CXXConstructorDecl 0x27bd560 <line:31:3> col:3 PositivePrivateTemplate 'void (const struct PositivePrivateTemplate<int> &)'

I'll make another patch for this.

This revision was automatically updated to reflect the committed changes.