[modules] Merge variable template specializations.

This commit is contained in:
Richard Smith 2022-04-19 14:40:52 -07:00
parent 954ba6045d
commit 63814be4fa
5 changed files with 19 additions and 4 deletions

View File

@ -2382,13 +2382,17 @@ ASTDeclReader::VisitVarTemplateSpecializationDeclImpl(
if (writtenAsCanonicalDecl) {
auto *CanonPattern = readDeclAs<VarTemplateDecl>();
if (D->isCanonicalDecl()) { // It's kept in the folding set.
// FIXME: If it's already present, merge it.
VarTemplateSpecializationDecl *CanonSpec;
if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
CanonPattern->getCommonPtr()->PartialSpecializations
.GetOrInsertNode(Partial);
CanonSpec = CanonPattern->getCommonPtr()
->PartialSpecializations.GetOrInsertNode(Partial);
} else {
CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
CanonSpec =
CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
}
// If we already have a matching specialization, merge it.
if (CanonSpec != D)
mergeRedeclarable<VarDecl>(D, CanonSpec, Redecl);
}
}

View File

@ -1 +1,3 @@
template<unsigned> class SmallString {};
template<int> int var_template = 0;

View File

@ -1,2 +1,4 @@
#include "a.h"
void f(SmallString<256>&);
template<typename T> void use_var_template(decltype(T() + var_template<0>)) {}

View File

@ -1,3 +1,6 @@
#include "a.h"
struct X { SmallString<256> ss; };
template<typename T> void use_var_template(decltype(T() + var_template<0>));
#include "b.h"

View File

@ -3,3 +3,7 @@
// expected-no-diagnostics
#include "c.h"
X x;
void test_var_template() {
use_var_template<int>(0);
}