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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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]
| clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp | ||
|---|---|---|
| 21 | A comment might be good to describe this struct. | |
| 23 | This can be written as const auto *Other = Nodes.getNodeAs<ValueDecl>(ID); following other patterns. | |
| 40 | Can be written using direct initialization as NotExtendedByDeclBoundToPredicate Predicate{ID}; | |
| 64 | This part looks like boilerplate in the middle of a specific implementation., isLanguageVersionSupported is mostly in the header file. | |
| 70 | This part look like boilerplate in the middle of a specific implementation., getCheckTraversalKind() is mostly in the header file. | |
| clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst | ||
| 11 | May be good to mention dangling references and resource leakage as potential issues. | |
| 19 | The below comment is not matching, do you want to write - | |
| clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp | ||
|---|---|---|
| 40 | Yes, but I followed like others are done. | |
| clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst | ||
| 19 | actually comment is +- fine, constructor to std::string will be called anyway, and for compiler I think those 2 are equal. | |
| clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst | ||
|---|---|---|
| 11 | There will be no dangling references and resource leakage because lifetime of temporary is extended by variable. | |
| clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst | ||
|---|---|---|
| 19 | but you have written below reference variable str is assigned a temporary object and there is no str variable. | |
| clang-tools-extra/docs/clang-tidy/checks/readability/reference-to-constructed-temporary.rst | ||
|---|---|---|
| 19 | Ok, that's actually a bug. It's value. | |
This LGTM, I will wait for two days before accepting the revision in case other reviewers might have some more comments/suggestions.
A comment might be good to describe this struct.