[PATCH] D46684: [Frontend] Don't skip function body when the return type is dependent on the template parameter.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 10 03:26:19 PDT 2018
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Otherwise clang will provide an unexpected diagnostic error.
Repository:
rC Clang
https://reviews.llvm.org/D46684
Files:
lib/Sema/SemaDecl.cpp
test/Index/skipped-auto-fn-templates.cpp
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 <typename T>
+auto foo(T a) {
+ return a;
+}
+
+int b = foo(0);
+// CHECK-NOT: error: function 'foo<int>' with deduced return type cannot be used before it is defined
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46684.146102.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180510/85e59f3c/attachment.bin>
More information about the cfe-commits
mailing list