Check for the overloadable attribute in all the appropriate syntactic locations

When forming the function type from a declarator, we look for an
overloadable attribute before issuing a diagnostic in C about a
function signature containing only .... When the attribute is present,
we allow such a declaration for compatibility with the overloading
rules in C++. However, we were not looking for the attribute in all of
the places it is legal to write it on a declarator and so we only
accepted the signature in some forms and incorrectly rejected the
signature in others.

We now check for the attribute preceding the declarator instead of only
being applied to the declarator directly.
This commit is contained in:
Aaron Ballman 2022-02-14 08:53:36 -05:00
parent 62c37fa2ac
commit 76032b0e3f
3 changed files with 17 additions and 1 deletions

View File

@ -77,6 +77,9 @@ Attribute Changes in Clang
- Added support for parameter pack expansion in `clang::annotate`.
- The ``overloadable`` attribute can now be written in all of the syntactic
locations a declaration attribute may appear. Fixes PR53805.
Windows Support
---------------

View File

@ -5237,7 +5237,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
// function is marked with the "overloadable" attribute. Scan
// for this attribute now.
if (!FTI.NumParams && FTI.isVariadic && !LangOpts.CPlusPlus)
if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable))
if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable) &&
!D.getDeclSpec().getAttributes().hasAttribute(
ParsedAttr::AT_Overloadable))
S.Diag(FTI.getEllipsisLoc(), diag::err_ellipsis_first_param);
if (FTI.NumParams && FTI.Params[0].Param == nullptr) {

View File

@ -248,3 +248,14 @@ void typeof_function_is_not_a_pointer() {
// if take_fn is passed a void (**)(void *), we'll get a warning.
take_fn(fn);
}
// PR53805
// We previously failed to consider the attribute being written before the
// declaration when considering whether to allow a variadic signature with no
// other parameters, and so we handled these cases differently.
__attribute__((overloadable)) void can_overload_1(...); // ok, was previously rejected
void can_overload_2(...) __attribute__((overloadable)); // ok
[[clang::overloadable]] void can_overload_3(...); // ok, was previously rejected
void can_overload_4 [[clang::overloadable]] (...); // ok
void cannot_overload(...) [[clang::overloadable]]; // expected-error {{ISO C requires a named parameter before '...'}} \
// expected-error {{'overloadable' attribute cannot be applied to types}}