Don't assert if we find a dependently-typed variable in the

redeclaration chain for an array.

A prior attempt to fix this in r280330 didn't handle the case where the
old variable is dependent and the new one is not.

It is notable and worrying that the test case in this example forms a
redeclaration chain for a non-dependent variable that includes a
declaration with a dependent type. We should probably fix that too.
This commit is contained in:
Richard Smith
2020-06-16 19:41:13 -07:00
parent 50155bcd46
commit 1b8125b041
2 changed files with 8 additions and 2 deletions
+2 -2
View File
@@ -3910,11 +3910,11 @@ void Sema::MergeVarDeclTypes(VarDecl *New, VarDecl *Old,
if (!NewArray->isIncompleteArrayType() && !NewArray->isDependentType()) {
for (VarDecl *PrevVD = Old->getMostRecentDecl(); PrevVD;
PrevVD = PrevVD->getPreviousDecl()) {
const ArrayType *PrevVDTy = Context.getAsArrayType(PrevVD->getType());
QualType PrevVDTy = PrevVD->getType();
if (PrevVDTy->isIncompleteArrayType() || PrevVDTy->isDependentType())
continue;
if (!Context.hasSameType(NewArray, PrevVDTy))
if (!Context.hasSameType(New->getType(), PrevVDTy))
return diagnoseVarDeclTypeMismatch(*this, New, PrevVD);
}
}
@@ -31,3 +31,9 @@ void foo3() {
void foo4() {
foo3<5>();
}
namespace NS {
int f() { extern int arr[3]; { extern int arr[]; } return 0; }
template<typename T> void g() { extern int arr[3]; extern T arr; }
template void g<int[]>();
}