diff options
author | Kim Gräsman <kim.grasman@gmail.com> | 2023-01-07 21:56:02 +0100 |
---|---|---|
committer | Kim Gräsman <kim.grasman@gmail.com> | 2023-03-05 14:43:19 +0100 |
commit | ffe6c3fe3a1dac9a4b577f4b07ef378ede933554 (patch) | |
tree | 77ed67f02fc7deaba97b11dfae3bbaea7c1fb1ec | |
parent | b1d446db03b50375ba7f9943635fa42afdc4635b (diff) |
Never report ignored types
CanIgnoreType is a little subtle, being a virtual method with very
different implementations for the primary visitor vs. the
instantiated-template visitor.
InstantiatedTemplateVisitor builds a resugar-map to associate canonical
types with their original spelling (e.g. re-binding canonical types to
any typedef used for template instantiation). Its derived CanIgnoreType
uses this map to determine whether Type instance can be ignored,
e.g. because it's a default template param or it's supposed to be
provided by the template, etc.
But CanIgnoreType was not used everywhere, so several paths would still
report types that were really known to be undesirable. This would lead
to types used inside templates to be reported in the instantiation
location, for example.
Change both the base and the instantiation-template implementations of
ReportTypeUse to call CanIgnoreType and always skip over ignored types.
This harmonization would not have been possible without the recent
tireless work of bolshakov-a improving resugaring and template handling
in general.
Fixes: #1004, #1110
-rw-r--r-- | iwyu.cc | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -1652,8 +1652,7 @@ class IwyuBaseAstVisitor : public BaseAstVisitor<Derived> { // with the warning message that iwyu emits. virtual void ReportTypeUse(SourceLocation used_loc, const Type* type, const char* comment = nullptr) { - // TODO(csilvers): figure out if/when calling CanIgnoreType() is correct. - if (!type) + if (CanIgnoreType(type)) return; // Enum type uses can be ignored. Their size is known (either implicitly @@ -2999,6 +2998,9 @@ class InstantiatedTemplateVisitor // clang desugars template types, so Foo<MyTypedef>() gets turned // into Foo<UnderlyingType>(). Try to convert back. type = ResugarType(type); + if (CanIgnoreType(type)) + return; + for (CacheStoringScope* storer : cache_storers_) storer->NoteReportedType(type); Base::ReportTypeUse(caller_loc(), type, comment); |