This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] performance-unnecessary-copy-initialization: Disable check when variable and initializer have different replaced template param types.
ClosedPublic

Authored by flx on Jul 14 2021, 1:15 PM.

Details

Summary

This can happen when a template with two parameter types is instantiated with a
single type. The fix would only be valid for this instantiation but fail for
others that rely on an implicit type conversion.

The test cases illustrate when the check should trigger and when not.

Diff Detail

Event Timeline

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

Nice!

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
178–183

nit: maybe just return the condition (instead of using if(...) return true)? that is
return VarTmpType->... != ...

271

typo: conversion

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

Addressed review feedback.

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
178–183

Done. Was left over from when there were debug statements there ;)