r321520 - [Frontend] Correctly handle instantiating ctors with skipped bodies
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 28 05:05:47 PST 2017
Author: ibiryukov
Date: Thu Dec 28 05:05:46 2017
New Revision: 321520
URL: http://llvm.org/viewvc/llvm-project?rev=321520&view=rev
Log:
[Frontend] Correctly handle instantiating ctors with skipped bodies
Summary:
Previsouly clang tried instantiating member initializers even if ctor
body was skipped, this caused spurious errors (see the test).
Reviewers: sepavloff, klimek
Reviewed By: sepavloff
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D41492
Added:
cfe/trunk/test/Index/skipped-bodies-ctors.cpp
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=321520&r1=321519&r2=321520&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Dec 28 05:05:46 2017
@@ -3932,22 +3932,22 @@ void Sema::InstantiateFunctionDefinition
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);
Added: cfe/trunk/test/Index/skipped-bodies-ctors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/skipped-bodies-ctors.cpp?rev=321520&view=auto
==============================================================================
--- cfe/trunk/test/Index/skipped-bodies-ctors.cpp (added)
+++ cfe/trunk/test/Index/skipped-bodies-ctors.cpp Thu Dec 28 05:05:46 2017
@@ -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
More information about the cfe-commits
mailing list