This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix typedefs handling in bugprone-dangling-handle
ClosedPublic

Authored by PiotrZSL on Apr 15 2023, 1:23 AM.

Details

Summary

Using 'hasUnqualifiedDesugaredType' to skip all type aliases when
checking for handle.

Fixes #38779

Diff Detail

Event Timeline

PiotrZSL created this revision.Apr 15 2023, 1:23 AM
Herald added a project: Restricted Project. · View Herald Transcript
PiotrZSL requested review of this revision.Apr 15 2023, 1:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2023, 1:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
carlosgalvezp added inline comments.Apr 15 2023, 3:07 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
55–57

Right now the test will no longer test classes that have the conversion operator written explicitly instead of via typedef. Do you think it's worth keeping the other implementation as well, or can we safely assume that basic_string is always implemented like this?

PiotrZSL marked an inline comment as done.Apr 15 2023, 3:14 AM
PiotrZSL added inline comments.
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
55–57

Both GCC (sv_type) & Clang (self_view) implement this using typedef.
But code will work fine also without typedef.

carlosgalvezp accepted this revision.Apr 15 2023, 3:22 AM
carlosgalvezp added inline comments.
clang-tools-extra/test/clang-tidy/checkers/bugprone/dangling-handle.cpp
55–57

But code will work fine also without typedef.

I guess we can't know if this will hold in the future unless we have an explicit test for it :) But I agree it's probably unlikely and if we had implemented this from scratch copying the pattern from GCC or Clang directly we would have ended up with this result.

This revision is now accepted and ready to land.Apr 15 2023, 3:22 AM
This revision was automatically updated to reflect the committed changes.
PiotrZSL marked an inline comment as done.