Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -5862,9 +5862,21 @@ // Instantiate non-default class member functions ... // .. except for certain kinds of template specializations. - if (TSK == TSK_ImplicitInstantiation && !ClassAttr->isInherited()) + if (TSK == TSK_ImplicitInstantiation && !ClassAttr->isInherited()) { + // But before that, make sure to instantiate default args for + // defaulted constructor. + CXXConstructorDecl *Ctor = dyn_cast(Member); + if (Ctor && Ctor->isDefaultConstructor() && + Ctor->hasOneParamOrDefaultArgs()) { + for (unsigned I = 0; I != Ctor->getNumParams(); ++I) { + S.CheckCXXDefaultArgExpr( + Member->getAttr()->getLocation(), Ctor, + Ctor->getParamDecl(I)); + S.DiscardCleanupsInEvaluationContext(); + } + } continue; - + } S.MarkFunctionReferenced(Class->getLocation(), MD); // The function will be passed to the consumer when its definition is Index: clang/test/SemaCXX/default-arg-closures.cpp =================================================================== --- clang/test/SemaCXX/default-arg-closures.cpp +++ clang/test/SemaCXX/default-arg-closures.cpp @@ -42,3 +42,10 @@ void f(const Default &d) { throw d; } + +template +class __declspec(dllexport) foo { + foo(int x = 0); +}; +template <> +foo::foo(int);