================
@@ -4814,18 +4814,29 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult
&Previous) {
}
// Merge the types.
- VarDecl *MostRecent = Old->getMostRecentDecl();
- if (MostRecent != Old) {
- MergeVarDeclTypes(New, MostRecent,
- mergeTypeWithPrevious(*this, New, MostRecent, Previous));
+ //
+ // If Old or any prior declaration in the redeclaration chain is invalid,
+ // MergeVarDeclTypes will return early without diagnosing a type conflict.
+ // Walk the chain (using redecls(), which goes newest-to-oldest) to find the
+ // most recent declaration that is valid so we can still detect type
+ // mismatches on New. If every prior declaration is invalid, skip the type
+ // merge entirely to avoid false positives; the redefinition logic below will
+ // still run and emit the appropriate diagnostic.
+ VarDecl *TypeOld = nullptr;
+ for (VarDecl *Prev : Old->redecls()) {
+ if (!Prev->isInvalidDecl()) {
+ TypeOld = Prev;
+ break;
+ }
+ }
----------------
memehdi14 wrote:
i am tryin by replacing the loop with llvm::find_if over Old->redecls(),
comparing against redecls_end() to keep the all-invalid-chain case handled,
matching the existing find_if-on-redecls() idiom a bit further up in this file
https://github.com/llvm/llvm-project/pull/228212
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits