diff options
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 22 | ||||
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 11 |
2 files changed, 17 insertions, 16 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index fb7fc109d2e..56858bcc7e6 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1512,7 +1512,7 @@ QualType Sema::SubstType(QualType T, } static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { - if (T->getType()->isInstantiationDependentType() || + if (T->getType()->isInstantiationDependentType() || T->getType()->isVariablyModifiedType()) return true; @@ -1521,23 +1521,13 @@ static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { return false; FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); - for (unsigned I = 0, E = FP.getNumParams(); I != E; ++I) { - ParmVarDecl *P = FP.getParam(I); - + for (ParmVarDecl *P : FP.getParams()) { // This must be synthesized from a typedef. if (!P) continue; - // The parameter's type as written might be dependent even if the - // decayed type was not dependent. - if (TypeSourceInfo *TSInfo = P->getTypeSourceInfo()) - if (TSInfo->getType()->isInstantiationDependentType()) - return true; - - // TODO: currently we always rebuild expressions. When we - // properly get lazier about this, we should use the same - // logic to avoid rebuilding prototypes here. - if (P->hasDefaultArg()) - return true; + // If there are any parameters, a new TypeSourceInfo that refers to the + // instantiated parameters must be built. + return true; } return false; @@ -1556,7 +1546,7 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, assert(!ActiveTemplateInstantiations.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack"); - + if (!NeedsInstantiationAsFunctionType(T)) return T; diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 073f2c50938..8a58afcaa41 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4276,6 +4276,17 @@ TEST(HasAncestor, AnonymousUnionMemberExpr) { declRefExpr(to(decl(hasAncestor(decl())))))); } +TEST(HasAncestor, NonParmDependentTemplateParmVarDeclRefExpr) { + EXPECT_TRUE(matches("struct PartitionAllocator {\n" + " template<typename T>\n" + " static int quantizedSize(int count) {\n" + " return count;\n" + " }\n" + " void f() { quantizedSize<int>(10); }\n" + "};", + declRefExpr(to(decl(hasAncestor(decl())))))); +} + TEST(HasParent, MatchesAllParents) { EXPECT_TRUE(matches( "template <typename T> struct C { static void f() { 42; } };" |

