Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -2758,6 +2758,46 @@ +
Matches expressions that are instantiation-dependent even if it is +neither type- nor value-dependent. + +In the following example, the expression sizeof(sizeof(T() + T())) +is instantiation-dependent (since it involves a template parameter T), +but is neither type- nor value-dependent, since the type of the inner +sizeof is known (std::size_t) and therefore the size of the outer +sizeof is known. + template<typename T> + void f(T x, T y) { sizeof(sizeof(T() + T()); } +expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T()) +
Matches expressions that are type-dependent because the template type +is not yet instantiated. + +For example, the expressions "x" and "x + y" are type-dependent in +the following code, but "y" is not type-dependent: + template<typename T> + void add(T x, int y) { + x + y; + } +expr(isTypeDependent()) matches x + y +
Matches expression that are value-dependent because they contain a +non-type template parameter. + +For example, the array bound of "Chars" in the following example is +value-dependent. + template<int Size> int f() { return Size; } +expr(isValueDependent()) matches return Size +
Matches non-static data members that are bit-fields of the specified bit width. Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -816,6 +816,48 @@ return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder); } +/// Matches expressions that are instantiation-dependent even if it is +/// neither type- nor value-dependent. +/// +/// In the following example, the expression sizeof(sizeof(T() + T())) +/// is instantiation-dependent (since it involves a template parameter T), +/// but is neither type- nor value-dependent, since the type of the inner +/// sizeof is known (std::size_t) and therefore the size of the outer +/// sizeof is known. +/// \code +/// template+/// void f(T x, T y) { sizeof(sizeof(T() + T()); } +/// \endcode +/// expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T()) +AST_MATCHER(Expr, isInstantiationDependent) { + return Node.isInstantiationDependent(); +} + +/// Matches expressions that are type-dependent because the template type +/// is not yet instantiated. +/// +/// For example, the expressions "x" and "x + y" are type-dependent in +/// the following code, but "y" is not type-dependent: +/// \code +/// template +/// void add(T x, int y) { +/// x + y; +/// } +/// \endcode +/// expr(isTypeDependent()) matches x + y +AST_MATCHER(Expr, isTypeDependent) { return Node.isTypeDependent(); } + +/// Matches expression that are value-dependent because they contain a +/// non-type template parameter. +/// +/// For example, the array bound of "Chars" in the following example is +/// value-dependent. +/// \code +/// template int f() { return Size; } +/// \endcode +/// expr(isValueDependent()) matches return Size +AST_MATCHER(Expr, isValueDependent) { return Node.isValueDependent(); } + /// Matches classTemplateSpecializations, templateSpecializationType and /// functionDecl where the n'th TemplateArgument matches the given InnerMatcher. /// Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -357,6 +357,7 @@ REGISTER_MATCHER(isExpansionInSystemHeader); REGISTER_MATCHER(isInteger); REGISTER_MATCHER(isIntegral); + REGISTER_MATCHER(isInstantiationDependent); REGISTER_MATCHER(isInTemplateInstantiation); REGISTER_MATCHER(isLambda); REGISTER_MATCHER(isListInitialization); @@ -376,8 +377,10 @@ REGISTER_MATCHER(isStaticStorageClass); REGISTER_MATCHER(isStruct); REGISTER_MATCHER(isTemplateInstantiation); + REGISTER_MATCHER(isTypeDependent); REGISTER_MATCHER(isUnion); REGISTER_MATCHER(isUnsignedInteger); + REGISTER_MATCHER(isValueDependent); REGISTER_MATCHER(isVariadic); REGISTER_MATCHER(isVirtual); REGISTER_MATCHER(isVirtualAsWritten); Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1768,6 +1768,48 @@ Matcher)); } +TEST(IsInstantiationDependent, MatchesNonValueTypeDependent) { + EXPECT_TRUE(matches( + "template void f() { (void) sizeof(sizeof(T() + T())); }", + expr(isInstantiationDependent()))); +} + +TEST(IsInstantiationDependent, MatchesValueDependent) { + EXPECT_TRUE(matches("template int f() { return T; }", + expr(isInstantiationDependent()))); +} + +TEST(IsInstantiationDependent, MatchesTypeDependent) { + EXPECT_TRUE(matches("template T f() { return T(); }", + expr(isInstantiationDependent()))); +} + +TEST(IsTypeDependent, MatchesTypeDependent) { + EXPECT_TRUE(matches("template T f() { return T(); }", + expr(isTypeDependent()))); +} + +TEST(IsTypeDependent, NotMatchesValueDependent) { + EXPECT_TRUE(notMatches("template int f() { return T; }", + expr(isTypeDependent()))); +} + +TEST(IsValueDependent, MatchesValueDependent) { + EXPECT_TRUE(matches("template int f() { return T; }", + expr(isValueDependent()))); +} + +TEST(IsValueDependent, MatchesTypeDependent) { + EXPECT_TRUE(matches("template T f() { return T(); }", + expr(isValueDependent()))); +} + +TEST(IsValueDependent, MatchesInstantiationDependent) { + EXPECT_TRUE(matches( + "template void f() { (void) sizeof(sizeof(T() + T())); }", + expr(isValueDependent()))); +} + TEST(IsExplicitTemplateSpecialization, DoesNotMatchPrimaryTemplate) { EXPECT_TRUE(notMatches(