Page MenuHomePhabricator

[clang-tidy] Add readability-reference-to-constructed-temporary check
Needs ReviewPublic

Authored by PiotrZSL on Mar 18 2023, 1:55 PM.

Details

Summary

Detects code where a temporary object is directly constructed by calling
a constructor or using an initializer list and immediately assigned to a
reference variable.

Diff Detail

Event Timeline

PiotrZSL created this revision.Mar 18 2023, 1:55 PM
Herald added a project: Restricted Project. · View Herald Transcript
PiotrZSL requested review of this revision.Mar 18 2023, 1:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2023, 1:55 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

There are 2 issues found in llvm repository:

  • llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp:721:22: warning: reference variable 'S' extends the lifetime of a just-constructed temporary object 'const StringRef', consider changing reference to value [readability-reference-to-constructed-temporary]
  • clang/lib/Sema/SemaChecking.cpp:10096:36: warning: reference variable 'AT2' extends the lifetime of a just-constructed temporary object 'const analyze_printf::ArgType', consider changing reference to value [readability-reference-to-constructed-temporary]
Eugene.Zelenko added inline comments.
clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
23

const auto *.

27

Ditto.

clang-tools-extra/test/clang-tidy/checkers/readability/reference-to-constructed-temporary.cpp
32

Excessive newline.

PiotrZSL updated this revision to Diff 506399.Mar 19 2023, 8:50 AM
PiotrZSL marked 3 inline comments as done.

Review comment fixes

PiotrZSL updated this revision to Diff 513693.Apr 14 2023, 11:39 AM

Ping + Rebase