Index: lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiate.cpp +++ lib/Sema/SemaTemplateInstantiate.cpp @@ -1512,7 +1512,7 @@ } static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { - if (T->getType()->isInstantiationDependentType() || + if (T->getType()->isInstantiationDependentType() || T->getType()->isVariablyModifiedType()) return true; @@ -1521,11 +1521,13 @@ return false; FunctionProtoTypeLoc FP = TL.castAs(); + bool AllParmsNull = true; for (unsigned I = 0, E = FP.getNumParams(); I != E; ++I) { ParmVarDecl *P = FP.getParam(I); // This must be synthesized from a typedef. if (!P) continue; + AllParmsNull = false; // The parameter's type as written might be dependent even if the // decayed type was not dependent. @@ -1540,7 +1542,9 @@ return true; } - return false; + // If there are any parameters, a new TypeSourceInfo that refers to the + // instantiated parameters must be built. + return !AllParmsNull && FP.getNumParams() > 0; } /// A form of SubstType intended specifically for instantiating the @@ -1556,7 +1560,7 @@ assert(!ActiveTemplateInstantiations.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack"); - + if (!NeedsInstantiationAsFunctionType(T)) return T; Index: unittests/ASTMatchers/ASTMatchersTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTest.cpp +++ unittests/ASTMatchers/ASTMatchersTest.cpp @@ -4225,6 +4225,17 @@ declRefExpr(to(decl(hasAncestor(decl())))))); } +TEST(HasAncestor, NonParmDependentTemplateParmVarDeclRefExpr) { + EXPECT_TRUE(matches("struct PartitionAllocator {\n" + " template\n" + " static int quantizedSize(int count) {\n" + " return count;\n" + " }\n" + " void f() { quantizedSize(10); }\n" + "};", + declRefExpr(to(decl(hasAncestor(decl())))))); +} + TEST(HasParent, MatchesAllParents) { EXPECT_TRUE(matches( "template struct C { static void f() { 42; } };"