Skip to content

Commit 76032b0

Browse files
committed
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.
1 parent 62c37fa commit 76032b0

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ Attribute Changes in Clang
7777

7878
- Added support for parameter pack expansion in `clang::annotate`.
7979

80+
- The ``overloadable`` attribute can now be written in all of the syntactic
81+
locations a declaration attribute may appear. Fixes PR53805.
82+
8083
Windows Support
8184
---------------
8285

clang/lib/Sema/SemaType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5237,7 +5237,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
52375237
// function is marked with the "overloadable" attribute. Scan
52385238
// for this attribute now.
52395239
if (!FTI.NumParams && FTI.isVariadic && !LangOpts.CPlusPlus)
5240-
if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable))
5240+
if (!D.getAttributes().hasAttribute(ParsedAttr::AT_Overloadable) &&
5241+
!D.getDeclSpec().getAttributes().hasAttribute(
5242+
ParsedAttr::AT_Overloadable))
52415243
S.Diag(FTI.getEllipsisLoc(), diag::err_ellipsis_first_param);
52425244

52435245
if (FTI.NumParams && FTI.Params[0].Param == nullptr) {

clang/test/Sema/overloadable.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,14 @@ void typeof_function_is_not_a_pointer() {
248248
// if take_fn is passed a void (**)(void *), we'll get a warning.
249249
take_fn(fn);
250250
}
251+
252+
// PR53805
253+
// We previously failed to consider the attribute being written before the
254+
// declaration when considering whether to allow a variadic signature with no
255+
// other parameters, and so we handled these cases differently.
256+
__attribute__((overloadable)) void can_overload_1(...); // ok, was previously rejected
257+
void can_overload_2(...) __attribute__((overloadable)); // ok
258+
[[clang::overloadable]] void can_overload_3(...); // ok, was previously rejected
259+
void can_overload_4 [[clang::overloadable]] (...); // ok
260+
void cannot_overload(...) [[clang::overloadable]]; // expected-error {{ISO C requires a named parameter before '...'}} \
261+
// expected-error {{'overloadable' attribute cannot be applied to types}}

0 commit comments

Comments
 (0)