-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iwyu suggest to include std::map for std::regex #1110
Comments
Interesting. Does it behave the same if you:
? We have some issues with template symbols being attributed to instatiation location, so I'm looking for a pattern. Also, is this with libc++ or libstdc++? |
Yeah, this was with libstdc++.
Switching to default-construction is fine:
Removing the copy keeps the bug:
|
Thanks! I wonder what the string ctor is doing with the map. Will look into this in more detail as time permits. |
A number of Visit... methods have been implemented in IwyuBaseASTVisitor over the years without any particular rationale. This means they affect traversal and use analysis for both template instantiations (InstantiatedTemplateVisitor) and regular IWYU logic (IwyuAstConsumer). Over time, we've seen several instances of confusing attribution with templates (particularly with the standard library), and it turns out this is the reason. This patch moves CXXMethodDecl, BinaryOperator, CXXCatchStmt and CXXForRangeStmt down to IwyuAstConsumer, which means they don't see through template instantiations any more. Fixes issues: include-what-you-use#927, include-what-you-use#944, include-what-you-use#1003, include-what-you-use#1004, include-what-you-use#1110, include-what-you-use#1149 format
A number of Visit... methods have been implemented in IwyuBaseASTVisitor over the years without any particular rationale. This means they affect traversal and use analysis for both template instantiations (InstantiatedTemplateVisitor) and regular IWYU logic (IwyuAstConsumer). Over time, we've seen several instances of confusing attribution with templates (particularly with the standard library), and it turns out this is the reason. This patch moves CXXMethodDecl, BinaryOperator, CXXCatchStmt and CXXForRangeStmt down to IwyuAstConsumer, which means they don't see through template instantiations any more. Fixes issues: include-what-you-use#927, include-what-you-use#944, include-what-you-use#1003, include-what-you-use#1004, include-what-you-use#1110, include-what-you-use#1149
InstantiatedTemplateVisitor does special traversal to collect a bunch of AST nodes to ignore, for various reasons. It also builds a resugar-map to associate desugared types with their original spelling (e.g. re-binding canonical types to any typedef used for template instantiation). CanIgnoreType uses these node sets to determine whether Type instance can be ignored. But CanIgnoreType is 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. Make sure InstantiatedTemplateVisitor::ReportTypeUse really does ignore types. Fixes: include-what-you-use#1004, include-what-you-use#1110
I've dug deep into the regex tree of headers, and found a clue. Any non-trivial constructor for This is not an explanation for why The IWYU behavior is caused by a long-standing problem with how we misinterpret types in template instantiations. All related issues are tagged template-spill . |
InstantiatedTemplateVisitor does special traversal to collect a bunch of AST nodes to ignore, for various reasons. It also builds a resugar-map to associate desugared types with their original spelling (e.g. re-binding canonical types to any typedef used for template instantiation). CanIgnoreType uses these node sets to determine whether Type instance can be ignored. But CanIgnoreType is 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. Make sure InstantiatedTemplateVisitor::ReportTypeUse really does ignore types. Fixes: include-what-you-use#1004, include-what-you-use#1110
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 these node sets 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. 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. Fixes: include-what-you-use#1004, include-what-you-use#1110
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. Fixes: include-what-you-use#1004, include-what-you-use#1110
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: include-what-you-use#1004, include-what-you-use#1110
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: include-what-you-use#1004, include-what-you-use#1110
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
Fixed on master as of ffe6c3f. |
Steps to reproduce:
The text was updated successfully, but these errors were encountered: