}
void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
- VisitRedeclarable(VD);
+ // Record the declaration -> global ID mapping.
+ Reader.DeclToID[VD] = ThisDeclID;
+
+ RedeclarableResult Redecl = VisitRedeclarable(VD);
VisitDeclaratorDecl(VD);
+
VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
VD->VarDeclBits.SClassAsWritten = (StorageClass)Record[Idx++];
VD->VarDeclBits.ThreadSpecified = Record[Idx++];
VD->VarDeclBits.NRVOVariable = Record[Idx++];
VD->VarDeclBits.CXXForRangeDecl = Record[Idx++];
VD->VarDeclBits.ARCPseudoStrong = Record[Idx++];
+
+ mergeRedeclarable(VD, Redecl);
+
if (uint64_t Val = Record[Idx++]) {
VD->setInit(Reader.ReadExpr(F));
if (Val > 1) {
}
// Functions with the same type and linkage match.
+ // FIXME: This needs to cope with function templates, merging of
+ //prototyped/non-prototyped functions, etc.
if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) {
FunctionDecl *FuncY = cast<FunctionDecl>(Y);
return (FuncX->getLinkage() == FuncY->getLinkage()) &&
FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType());
}
+ // Variables with the same type and linkage match.
+ if (VarDecl *VarX = dyn_cast<VarDecl>(X)) {
+ VarDecl *VarY = cast<VarDecl>(Y);
+ return (VarX->getLinkage() == VarY->getLinkage()) &&
+ VarX->getASTContext().hasSameType(VarX->getType(), VarY->getType());
+ }
// FIXME: Many other cases to implement.
return false;
func2(i); // expected-error{{call to 'func2' is ambiguous}}
}
+void testVarMerge(int i) {
+ var1 = i;
+ // in other files: expected-note 2{{candidate found by name lookup is 'var2'}}
+ var2 = i; // expected-error{{reference to 'var2' is ambiguous}}
+ // in other files: expected-note 2{{candidate found by name lookup is 'var3'}}
+ var3 = i; // expected-error{{reference to 'var3' is ambiguous}}
+}
+
// Test redeclarations of entities in explicit submodules, to make
// sure we're maintaining the declaration chains even when normal name
// lookup can't see what we're looking for.