Skip to content

Commit d807ce7

Browse files
authored
Merge pull request #36554 from zoecarver/cxx/fix-no-pattern-constexpr-static-data-member
[cxx-interop] Don't instantiate empty class template specializations.
2 parents c148332 + 4174322 commit d807ce7

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,8 +3752,9 @@ namespace {
37523752
// any instantiation errors.
37533753
for (auto member : decl->decls()) {
37543754
if (auto varDecl = dyn_cast<clang::VarDecl>(member)) {
3755-
Impl.getClangSema()
3756-
.InstantiateVariableDefinition(varDecl->getLocation(), varDecl);
3755+
if (varDecl->getTemplateInstantiationPattern())
3756+
Impl.getClangSema()
3757+
.InstantiateVariableDefinition(varDecl->getLocation(), varDecl);
37573758
}
37583759
}
37593760

test/Interop/Cxx/templates/Inputs/explicit-class-specialization.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,16 @@ template <class T, class... Ts> class HasSpecializations<int, T, Ts...> {
6161
enum Maybe : int { No, Yes };
6262
};
6363

64+
template <class>
65+
struct HasEmptySpecializationAndStaticDateMember {
66+
inline static const bool value = false;
67+
};
68+
69+
template <>
70+
struct HasEmptySpecializationAndStaticDateMember<char> {
71+
inline static const bool value = true;
72+
};
73+
74+
using HasEmptySpecializationAndStaticDateMemberInt = HasEmptySpecializationAndStaticDateMember<int>;
75+
6476
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_EXPLICIT_CLASS_SPECIALIZATION_H
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=ExplicitClassSpecialization -I %S/Inputs -source-filename=x -enable-cxx-interop | %FileCheck %s
2+
3+
// CHECK: struct __CxxTemplateInst41HasEmptySpecializationAndStaticDateMemberIiE {
4+
// CHECK: static let value: Bool
5+
// CHECK: }
6+
7+
// CHECK: struct __CxxTemplateInst41HasEmptySpecializationAndStaticDateMemberIcE {
8+
// CHECK: static let value: Bool
9+
// CHECK: }

0 commit comments

Comments
 (0)