summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Grasman <kim.grasman@gmail.com>2017-05-02 17:15:44 +0200
committerKim Gräsman <kim.grasman@gmail.com>2017-05-17 19:48:32 +0200
commit34baf6e65ccd12ff983e4ebefdd7e1140f9878a2 (patch)
tree336750d2382a4e2d10022413049ff875bde95f29
parent669dd9334565675ca82d1fb54703eb2f325aa866 (diff)
Equate alias declarations and typedef in templates
Typedefs are exempted from IWYU checks in templates, so treat C++11 alias declarations the same. (side note: this behavior is broken, but at least now it's consistent) Fixes issue #412.
-rw-r--r--iwyu.cc3
-rwxr-xr-xrun_iwyu_tests.py1
-rw-r--r--tests/cxx/typedef_in_template.cc6
3 files changed, 9 insertions, 1 deletions
diff --git a/iwyu.cc b/iwyu.cc
index 1c4297a..196a574 100644
--- a/iwyu.cc
+++ b/iwyu.cc
@@ -205,6 +205,7 @@ using clang::TranslationUnitDecl;
using clang::Type;
using clang::TypeLoc;
using clang::TypedefDecl;
+using clang::TypedefNameDecl;
using clang::TypedefType;
using clang::UnaryExprOrTypeTraitExpr;
using clang::UsingDecl;
@@ -3042,7 +3043,7 @@ class InstantiatedTemplateVisitor
// you do 'Foo<MyClass>::value_type m;'?
for (const ASTNode* ast_node = current_ast_node();
ast_node != caller_ast_node_; ast_node = ast_node->parent()) {
- if (ast_node->IsA<TypedefDecl>())
+ if (ast_node->IsA<TypedefNameDecl>())
return Base::VisitSubstTemplateTypeParmType(type);
}
diff --git a/run_iwyu_tests.py b/run_iwyu_tests.py
index b0252ab..6e36c04 100755
--- a/run_iwyu_tests.py
+++ b/run_iwyu_tests.py
@@ -106,6 +106,7 @@ class OneIwyuTest(unittest.TestCase):
'prefix_header_includes_add.cc': prefix_headers,
'prefix_header_includes_keep.cc': prefix_headers,
'prefix_header_includes_remove.cc': prefix_headers,
+ 'typedef_in_template.cc': ['-std=c++11'],
}
include_map = {
'alias_template.cc': ['.'],
diff --git a/tests/cxx/typedef_in_template.cc b/tests/cxx/typedef_in_template.cc
index 5e5dacc..48721d7 100644
--- a/tests/cxx/typedef_in_template.cc
+++ b/tests/cxx/typedef_in_template.cc
@@ -15,6 +15,9 @@ class Container {
// Should not be an iwyu violation for T
typedef T value_type;
+ // C++11 alias declaration, should not be an iwyu violation for T
+ using alias_type = T;
+
// IWYU: Pair is...*typedef_in_template-i1.h
typedef Pair<T,T> pair_type;
};
@@ -34,6 +37,9 @@ void Declarations() {
// IWYU: Class needs a declaration
Container<Class>::pair_type pt;
+
+ // IWYU: Class needs a declaration
+ Container<Class>::alias_type at;
}