This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] performance-unnecessary-copy-initialization: Create option to exclude container types from triggering the check.
ClosedPublic

Authored by flx on Jul 16 2021, 11:46 AM.

Details

Summary

Add string list option of type names analagous to AllowedTypes which lets
users specify a list of ExcludedContainerTypes.

Types matching this list will not trigger the check when an expensive variable
is copy initialized from a const accessor method they provide, i.e.:

ExcludedContainerTypes = 'ExcludedType'

void foo() {
  ExcludedType<ExpensiveToCopy> Container;
  const ExpensiveToCopy NecessaryCopy = Container.get();
}

Even though an expensive to copy variable is copy initialized the check does not
trigger because the container type is excluded.

This is useful for container types that don't own their data, such as view types
where modification of the returned references in other places cannot be reliably
tracked, or const incorrect types.

Diff Detail

Event Timeline

flx created this revision.Jul 16 2021, 11:46 AM
flx requested review of this revision.Jul 16 2021, 11:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2021, 11:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ymandel accepted this revision.Jul 16 2021, 1:29 PM

Looks good. I was only a little confused by the first sentence of the option description.

clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
53

should this "not" be here?

This revision is now accepted and ready to land.Jul 16 2021, 1:29 PM
flx updated this revision to Diff 360865.Jul 22 2021, 10:05 AM

Add test file for the new option.

flx marked an inline comment as done.Jul 22 2021, 10:06 AM

I also added a file testing the new option.

clang-tools-extra/docs/clang-tidy/checks/performance-unnecessary-copy-initialization.rst
53

Yeah, that makes it more clear. Done.

ymandel accepted this revision.Jul 22 2021, 10:07 AM
This revision was automatically updated to reflect the committed changes.
flx marked an inline comment as done.