Skip to content

Commit c41f6ff

Browse files
committed
[clang] Fix missing initializer for inline static template member with auto caused by delayed template instantiation.
[Clang] Fix missing initializer for inline static template member with auto caused by delayed template instantiation.
1 parent 9b10512 commit c41f6ff

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6027,8 +6027,12 @@ void Sema::BuildVariableInstantiation(
60276027
Context.setManglingNumber(NewVar, Context.getManglingNumber(OldVar));
60286028
Context.setStaticLocalNumber(NewVar, Context.getStaticLocalNumber(OldVar));
60296029

6030+
bool VarTemplateWithAutoType =
6031+
OldVar->getTypeSourceInfo()->getType()->getAs<AutoType>();
6032+
60306033
// Figure out whether to eagerly instantiate the initializer.
6031-
if (InstantiatingVarTemplate || InstantiatingVarTemplatePartialSpec) {
6034+
if (!VarTemplateWithAutoType &&
6035+
(InstantiatingVarTemplate || InstantiatingVarTemplatePartialSpec)) {
60326036
// We're producing a template. Don't instantiate the initializer yet.
60336037
} else if (NewVar->getType()->isUndeducedType()) {
60346038
// We need the type to complete the declaration of the variable.

clang/test/SemaTemplate/cxx17-inline-variables.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,15 @@ template <typename T> constexpr int A<T>::n = sizeof(A) + sizeof(T);
2727
template <typename T> inline constexpr int A<T>::m = sizeof(A) + sizeof(T);
2828
static_assert(A<int>().f() == 5);
2929
static_assert(A<int>().g() == 5);
30+
31+
template <typename T> struct InlineAuto {
32+
template <typename G> inline static auto var = 5;
33+
};
34+
35+
template <typename> struct PartialInlineAuto {
36+
template <typename, typename> inline static auto var = 6;
37+
template <typename T> inline static auto var<int, T> = 7;
38+
};
39+
40+
int inlineauot = InlineAuto<int>::var<int>;
41+
int partialinlineauot = PartialInlineAuto<int>::var<int, int>;

0 commit comments

Comments
 (0)