diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -5111,7 +5111,11 @@ InstantiateVariableInitializer(NewVar, OldVar, TemplateArgs); } else if (InstantiatingSpecFromTemplate || (OldVar->isInline() && OldVar->isThisDeclarationADefinition() && - !NewVar->isThisDeclarationADefinition())) { + !NewVar->isThisDeclarationADefinition() && + // On Microsoft's ABI, the new var's initializer will be part of + // the definition. But, we still want to instanciate it so that + // we can catch instantiation errors. + !Context.getTargetInfo().getCXXABI().isMicrosoft())) { // Delay instantiation of the initializer for variable template // specializations or inline static data members until a definition of the // variable is needed. diff --git a/clang/test/SemaCXX/windows-data-member-instantiation-errors.cpp b/clang/test/SemaCXX/windows-data-member-instantiation-errors.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/windows-data-member-instantiation-errors.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -verify -std=c++11 %s +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -verify -std=c++17 %s + +template +struct GetTypeValue { + // expected-error@+1{{type 'int' cannot be used prior to '::' because it has no members}} + static constexpr const bool value = T::value; +}; + +using Invalid = GetTypeValue; + +// expected-note@+1{{in instantiation of template class 'GetTypeValue' requested here}} +void test(Invalid) {} + +// expected-note@+2{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const S &' for 1st argument}} +// expected-note@+1{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'S &&' for 1st argument}} +struct S {}; + +template +struct MakeS { + // expected-error@+1{{no viable conversion from 'int' to 'const S'}} + static constexpr const S value = T(); +}; + +using Invalid2 = MakeS; + +// expected-note@+1{{in instantiation of template class 'MakeS' requested here}} +void test2(Invalid2) {}