From: Douglas Gregor Date: Mon, 9 May 2011 20:45:16 +0000 (+0000) Subject: When determining whether we need to instantiate a function type, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c056c1792eac0717640f1f48b3739cc9a98ee413;p=clang When determining whether we need to instantiate a function type, also consider whether any of the parameter types (as written, prior to decay) are dependent. Fixes PR9880 and . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131099 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 03c2befbc5..564f099ad9 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1388,6 +1388,12 @@ static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { for (unsigned I = 0, E = FP.getNumArgs(); I != E; ++I) { ParmVarDecl *P = FP.getArg(I); + // 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()->isDependentType()) + 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. diff --git a/test/SemaTemplate/instantiate-function-1.cpp b/test/SemaTemplate/instantiate-function-1.cpp index 688d009526..5406fbcd1b 100644 --- a/test/SemaTemplate/instantiate-function-1.cpp +++ b/test/SemaTemplate/instantiate-function-1.cpp @@ -225,3 +225,25 @@ namespace PR7016 { template void f() { T x = x; } template void f(); } + +namespace PR9880 { + struct lua_State; + struct no_tag { char a; }; // (A) + struct yes_tag { long a; long b; }; // (A) + + template + struct HasIndexMetamethod { + template + static no_tag check(...); + template + static yes_tag check(char[sizeof(&U::luaIndex)]); + enum { value = sizeof(check(0)) == sizeof(yes_tag) }; + }; + + class SomeClass { + public: + int luaIndex(lua_State* L); + }; + + int i = HasIndexMetamethod::value; +}