delete Next;
}
+ /// \brief Whether this attribute should be merged to new
+ /// declarations.
+ virtual bool isMerged() const { return true; }
+
Kind getKind() const { return AttrKind; }
Attr *getNext() { return Next; }
public:
OverloadableAttr() : Attr(Overloadable) { }
+ virtual bool isMerged() const { return false; }
+
static bool classof(const Attr *A) { return A->getKind() == Overloadable; }
static bool classof(const OverloadableAttr *) { return true; }
};
DIAG(err_attribute_overloadable_not_function, ERROR,
"'overloadable' attribute can only be applied to a function")
DIAG(err_attribute_overloadable_missing, ERROR,
- "overloaded function %0 must have the 'overloadable' attribute")
+ "%select{overloaded function|redeclaration of}0 %1 must have the 'overloadable' attribute")
DIAG(note_attribute_overloadable_prev_overload, NOTE,
"previous overload of function is here")
Attr *attr = const_cast<Attr*>(Old->getAttrs()), *tmp;
while (attr) {
- tmp = attr;
- attr = attr->getNext();
+ tmp = attr;
+ attr = attr->getNext();
- if (!DeclHasAttr(New, tmp)) {
- tmp->setInherited(true);
- New->addAttr(tmp);
+ if (!DeclHasAttr(New, tmp) && tmp->isMerged()) {
+ tmp->setInherited(true);
+ New->addAttr(tmp);
} else {
- tmp->setNext(0);
- delete(tmp);
+ tmp->setNext(0);
+ delete(tmp);
}
}
// there's no more work to do here; we'll just add the new
// function to the scope.
OverloadedFunctionDecl::function_iterator MatchedDecl;
+
+ if (!getLangOptions().CPlusPlus &&
+ AllowOverloadingOfFunction(PrevDecl, Context))
+ OverloadableAttrRequired = true;
+
if (!AllowOverloadingOfFunction(PrevDecl, Context) ||
!IsOverload(NewFD, PrevDecl, MatchedDecl)) {
Decl *OldDecl = PrevDecl;
}
}
}
-
- // If we're in C, this new declaration better have the
- // "overloadable" attribute on it.
- if (!getLangOptions().CPlusPlus &&
- PrevDecl->getAttr<OverloadableAttr>())
- OverloadableAttrRequired = true;
}
if (D.getCXXScopeSpec().isSet() &&
// If a function name is overloadable in C, then every function
// with that name must be marked "overloadable".
Diag(NewFD->getLocation(), diag::err_attribute_overloadable_missing)
- << NewFD;
+ << Redeclaration << NewFD;
if (PrevDecl)
Diag(PrevDecl->getLocation(),
diag::note_attribute_overloadable_prev_overload);
int var __attribute__((overloadable)); // expected-error{{'overloadable' attribute can only be applied to a function}}
-int *f(int) __attribute__((overloadable)); // expected-note{{previous overload of function is here}}
+int *f(int) __attribute__((overloadable)); // expected-note 2{{previous overload of function is here}}
float *f(float); // expected-error{{overloaded function 'f' must have the 'overloadable' attribute}}
-int *f(int); // expected-note{{previous declaration is here}}
+int *f(int); // expected-error{{redeclaration of 'f' must have the 'overloadable' attribute}} \
+ // expected-note{{previous declaration is here}}
double *f(double) __attribute__((overloadable)); // okay, new
void test_f(int iv, float fv, double dv) {
}
double *f(int) __attribute__((overloadable)); // expected-error{{conflicting types for 'f'}}
+
+