[PATCH] D105287: Fix an accepts-invalid issue with [[]] attributes in the type position in C

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 1 08:09:01 PDT 2021


aaron.ballman added a comment.

> I guess I don't see how this patch 'works' here. I don't see anything preventing the type-location in C, but not C++?

See comments in the code, I left one where the interesting bit is.



================
Comment at: clang/lib/Sema/SemaType.cpp:8091
+      // A [[]] attribute on a declarator chunk must appertain to a type.
+      if (attr.isStandardAttributeSyntax() && TAL == TAL_DeclChunk) {
         state.getSema().Diag(attr.getLoc(), diag::err_attribute_not_type_attr)
----------------
This bit right here is the important bit for diagnosing in the type position (similar changes are fixing similar issues). `isCXX11Attribute()` tests that the attribute syntax is `AS_CXX11` exclusively and ignores that there's a `AS_C2x` -- the fix is to check for either parsed syntax.


================
Comment at: clang/test/Sema/attr-c2x.c:14
 
-void foo(void *c) [[clang::overloadable]];
-void foo(char *c) [[clang::overloadable]];
+[[clang::overloadable]] void foo(void *c);
+[[clang::overloadable]] void foo(char *c);
----------------
erichkeane wrote:
> Do we have a test to validate that the previous syntax isn't allowed?  I don't see any being added, but I might be missing it.
It looks like we don't have any coverage that you can't apply overloadable to a type, I can add it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105287/new/

https://reviews.llvm.org/D105287



More information about the cfe-commits mailing list