-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore the class qualifier in out of line methods
Instead of aborting the AST traversal completely whenever a class qualifier is found, skip the traversal of the class template and its methods in such contexts only. The reasoning here is that a class template will be inspected during the regular instantiation anyway, so there is no need to duplicate efforts. Apart from performance implications, scanning the template here makes IWYU report all template parameters as if specified explicitly by the user (effectively ignoring default template params). For example, std::allocator would get reported as a full-use during a call to push_back() because it is defined outside of the std::vector class. Closes #533
- Loading branch information
Showing
7 changed files
with
157 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//===--- out_of_line-dep-char.h - 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_CHAR_H_ | ||
#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_CHAR_H_ | ||
|
||
void Dependent(char); | ||
|
||
#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_CHAR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//===--- out_of_line-dep-int.h - 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_INT_H_ | ||
#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_INT_H_ | ||
|
||
void Dependent(int); | ||
|
||
#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_INT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//===--- out_of_line-dep.h - 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_H_ | ||
#define INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_H_ | ||
|
||
#include "out_of_line-dep-int.h" | ||
#include "out_of_line-dep-char.h" | ||
|
||
#endif // INCLUDE_WHAT_YOU_USE_TESTS_CXX_OUT_OF_LINE_DEP_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//===--- out_of_line.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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "out_of_line-dep.h" | ||
|
||
template <class T, class U = char> | ||
struct Class { | ||
using Type = T; | ||
|
||
void MethodIn() { Dependent(T()); } | ||
void MethodOut(); | ||
|
||
static void MethodStaticIn() { Dependent(T()); } | ||
static void MethodStaticOut(); | ||
}; | ||
|
||
template <class T, class U> | ||
void Class<T, U>::MethodOut() { | ||
Dependent(T()); | ||
} | ||
|
||
template <class T, class U> | ||
void Class<T, U>::MethodStaticOut() { | ||
Dependent(T()); | ||
} | ||
|
||
template <> | ||
void Class<int, int>::MethodOut() { | ||
// IWYU: Dependent is.*dep-int.h | ||
Dependent(Type()); | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
//Inline template method | ||
Class<int> c; | ||
// IWYU: Dependent is.*dep-int.h | ||
c.MethodIn(); | ||
|
||
//Out-of-line template method | ||
Class<int> c2; | ||
// IWYU: Dependent is.*dep-int.h | ||
c2.MethodOut(); | ||
|
||
//A explicit specialization of MethodOut(). It does not | ||
//require Dependent(int) here, because it must be already | ||
//available at the definition. | ||
Class<int, int> c3; | ||
c3.MethodOut(); | ||
|
||
//Inline static method | ||
// IWYU: Dependent is.*dep-int.h | ||
Class<int>::MethodStaticIn(); | ||
|
||
//Out-of-line static method | ||
// IWYU: Dependent is.*dep-int.h | ||
Class<int>::MethodStaticOut(); | ||
} | ||
|
||
/**** IWYU_SUMMARY | ||
tests/cxx/out_of_line.cc should add these lines: | ||
#include "out_of_line-dep-int.h" | ||
tests/cxx/out_of_line.cc should remove these lines: | ||
- #include "out_of_line-dep.h" // lines XX-XX | ||
The full include-list for tests/cxx/out_of_line.cc: | ||
#include "out_of_line-dep-int.h" // for Dependent | ||
***** IWYU_SUMMARY */ |