[clang] 76032b0 - Check for the overloadable attribute in all the appropriate syntactic locations

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 14 05:54:34 PST 2022


Author: Aaron Ballman
Date: 2022-02-14T08:54:21-05:00
New Revision: 76032b0e3f58d4abe8d00ac61ff1b2044e076ba7

URL: https://github.com/llvm/llvm-project/commit/76032b0e3f58d4abe8d00ac61ff1b2044e076ba7
DIFF: https://github.com/llvm/llvm-project/commit/76032b0e3f58d4abe8d00ac61ff1b2044e076ba7.diff

LOG: 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.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaType.cpp
    clang/test/Sema/overloadable.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4a63959412678..26860d3118020 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
 ---------------
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index ab47e9f03eaf2..74969749e54ae 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -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) {

diff  --git a/clang/test/Sema/overloadable.c b/clang/test/Sema/overloadable.c
index b520d76f9e7e8..e9bbdeab7f66c 100644
--- a/clang/test/Sema/overloadable.c
+++ b/clang/test/Sema/overloadable.c
@@ -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 
diff erently.
+__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}}


        


More information about the cfe-commits mailing list