Go through alias template to handle aliased template specialization (issue #150).
Test case created with the help of Kim Gräsman.
This commit is contained in:
parent
57a544b83c
commit
8fd93dc87f
6
iwyu.cc
6
iwyu.cc
|
@ -3095,6 +3095,12 @@ class InstantiatedTemplateVisitor
|
|||
if (current_ast_node()->in_forward_declare_context())
|
||||
return true;
|
||||
|
||||
while (type->isTypeAlias()) {
|
||||
type = DynCastFrom(type->getAliasedType().getTypePtr());
|
||||
if (!type)
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we're a dependent type, we only try to be analyzed if we're
|
||||
// in the precomputed list -- in general, the only thing clang
|
||||
// tells us about dependent types is their name (which is all we
|
||||
|
|
|
@ -79,6 +79,7 @@ class OneIwyuTest(unittest.TestCase):
|
|||
self.Include('prefix_header_includes-d3.h'),
|
||||
self.Include('prefix_header_includes-d4.h')]
|
||||
clang_flags_map = {
|
||||
'alias_template.cc': ['-std=c++11'],
|
||||
'auto_type_within_template.cc': ['-std=c++11'],
|
||||
'conversion_ctor.cc': ['-std=c++11'],
|
||||
'ms_inline_asm.cc': ['-fms-extensions'],
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
//===--- alias_template.cc - test input file for iwyu ---------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Tests alias templates. Does not test type aliases.
|
||||
|
||||
#include "tests/cxx/direct.h"
|
||||
|
||||
template<class T> struct FullUseTemplateArg {
|
||||
char argument[sizeof(T)];
|
||||
};
|
||||
|
||||
// Test that we go through alias template and handle aliased template
|
||||
// specialization.
|
||||
template<class T> using Alias = FullUseTemplateArg<T>;
|
||||
// IWYU: IndirectClass needs a declaration
|
||||
// IWYU: IndirectClass is...*indirect.h
|
||||
Alias<IndirectClass> alias;
|
||||
|
||||
// Test following through entire chain of aliases.
|
||||
template<class T> using AliasChain1 = FullUseTemplateArg<T>;
|
||||
template<class T> using AliasChain2 = AliasChain1<T>;
|
||||
// IWYU: IndirectClass needs a declaration
|
||||
// IWYU: IndirectClass is...*indirect.h
|
||||
AliasChain2<IndirectClass> aliasChain;
|
||||
|
||||
// Test the case when aliased type isn't a template specialization.
|
||||
template<class T> using Pointer = T*;
|
||||
Pointer<int> intPtr;
|
||||
|
||||
/**** IWYU_SUMMARY
|
||||
|
||||
tests/cxx/alias_template.cc should add these lines:
|
||||
#include "tests/cxx/indirect.h"
|
||||
|
||||
tests/cxx/alias_template.cc should remove these lines:
|
||||
- #include "tests/cxx/direct.h" // lines XX-XX
|
||||
|
||||
The full include-list for tests/cxx/alias_template.cc:
|
||||
#include "tests/cxx/indirect.h" // for IndirectClass
|
||||
|
||||
***** IWYU_SUMMARY */
|
Loading…
Reference in New Issue