[PATCH] D41492: [Frontend] Correctly handle instantiating ctors with skipped bodies
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 21 07:35:45 PST 2017
ilya-biryukov created this revision.
ilya-biryukov added reviewers: sepavloff, klimek.
Previsouly clang tried instantiating member initializers even if ctor
body was skipped, this caused spurious errors (see the test).
Repository:
rC Clang
https://reviews.llvm.org/D41492
Files:
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/Index/skipped-bodies-ctors.cpp
Index: test/Index/skipped-bodies-ctors.cpp
===================================================================
--- /dev/null
+++ test/Index/skipped-bodies-ctors.cpp
@@ -0,0 +1,16 @@
+// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s 2>&1 \
+// RUN: | FileCheck --implicit-check-not "error:" %s
+
+
+template <class T>
+struct Foo {
+ template <class = int>
+ Foo(int &a) : a(a) {
+ }
+
+ int &a;
+};
+
+
+int bar = Foo<int>(bar).a + Foo<int>(bar).a;
+// CHECK-NOT: error: constructor for 'Foo<int>' must explicitly initialize the reference
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3928,22 +3928,22 @@
TemplateArgs))
return;
- if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(Function)) {
- // If this is a constructor, instantiate the member initializers.
- InstantiateMemInitializers(Ctor, cast<CXXConstructorDecl>(PatternDecl),
- TemplateArgs);
-
- // If this is an MS ABI dllexport default constructor, instantiate any
- // default arguments.
- if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
- Ctor->isDefaultConstructor()) {
- InstantiateDefaultCtorDefaultArgs(*this, Ctor);
- }
- }
-
if (PatternDecl->hasSkippedBody()) {
ActOnSkippedFunctionBody(Function);
} else {
+ if (CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(Function)) {
+ // If this is a constructor, instantiate the member initializers.
+ InstantiateMemInitializers(Ctor, cast<CXXConstructorDecl>(PatternDecl),
+ TemplateArgs);
+
+ // If this is an MS ABI dllexport default constructor, instantiate any
+ // default arguments.
+ if (Context.getTargetInfo().getCXXABI().isMicrosoft() &&
+ Ctor->isDefaultConstructor()) {
+ InstantiateDefaultCtorDefaultArgs(*this, Ctor);
+ }
+ }
+
// Instantiate the function body.
StmtResult Body = SubstStmt(Pattern, TemplateArgs);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41492.127882.patch
Type: text/x-patch
Size: 2245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171221/e7007ef1/attachment.bin>
More information about the cfe-commits
mailing list