This is an archive of the discontinued LLVM Phabricator instance.

[Clang-tidy] Check the existence of ElaboratedType's qualifiers
ClosedPublic

Authored by junaire on Feb 16 2022, 8:03 AM.

Details

Summary

The ElaboratedType can have no qualifiers, so we should check it before
use.

Fix #issue53874(https://github.com/llvm/llvm-project/issues/53874)

Diff Detail

Event Timeline

junaire created this revision.Feb 16 2022, 8:03 AM
junaire requested review of this revision.Feb 16 2022, 8:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2022, 8:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cloudhan added a subscriber: cloudhan.EditedFeb 16 2022, 9:39 PM

As the original bug reporter, I don't think this is a proper fix for it. There seems to be some kind of bug deep in the frontend. This just hide it anyway.

As the original bug reporter, I don't think this is a proper fix for it. There seems to be some kind of bug deep in the frontend. This just hide it anyway.

Yeah, maybe there's a deeper issue need to be dug into. I just found the code below doesn't work as well:

namespace N {

struct S{
        static int i;
} s;
}

int main()
{
        return N::s.i;
}

Without this fix, clang-tidy will crash, but after applying this patch, clang-tidy gives the wrong fixhint:

/home/jun/workground/demo.cpp:10:9: warning: static member accessed through instance [readability-static-accessed-through-instance]
        return N::s.i;
               ^~~~~
               struct S::
      // should be N::S::

I will try to look into this issue, any comments about it are welcome :-)

junaire updated this revision to Diff 409510.Feb 17 2022, 12:36 AM
  • Only suppress canonical types when it's a TypedefNameType.
  • Add more tests.
junaire updated this revision to Diff 409511.Feb 17 2022, 12:38 AM

Simplify code a little bit.

Gentle ping~

MTC added a subscriber: MTC.Feb 22 2022, 5:54 PM

Gentle ping~

Gentle ping~

LegalizeAdulthood accepted this revision.Mar 1 2022, 7:10 AM

Fix one nit and ship

clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
74

Simplify to !BaseExpr->getType()->isTypedefNameType();

This revision is now accepted and ready to land.Mar 1 2022, 7:10 AM