Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -12637,8 +12637,12 @@ // rest of the file. // We cannot skip the body of a function with an undeduced return type, // because any callers of that function need to know the type. + // We cannot skip the body of a function template with an 'auto' return type + // which is dependent on a template parameter, we need to see the function + // body before using it. if (const FunctionDecl *FD = D->getAsFunction()) - if (FD->isConstexpr() || FD->getReturnType()->isUndeducedType()) + if (FD->isConstexpr() || FD->getReturnType()->isUndeducedType() || + FD->getReturnType()->isInstantiationDependentType()) return false; return Consumer.shouldSkipFunctionBody(D); } Index: test/Index/skipped-auto-fn-templates.cpp =================================================================== --- /dev/null +++ test/Index/skipped-auto-fn-templates.cpp @@ -0,0 +1,10 @@ +// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s 2>&1 \ +// RUN: | FileCheck %s + +template +auto foo(T a) { + return a; +} + +int b = foo(0); +// CHECK-NOT: error: function 'foo' with deduced return type cannot be used before it is defined