[PATCH] D157572: [clang] Add `[[clang::library_extension]]` attribute

Nikolas Klauser via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 21 13:03:36 PDT 2023


philnik added a comment.

In D157572#4604482 <https://reviews.llvm.org/D157572#4604482>, @aaron.ballman wrote:

>> This allows standard libraries to mark symbols as extensions, so the compiler can generate extension warnings when they are used.
>
> Huh, so this is basically the opposite of the `__extension__` macro (which is used to silence extension warnings)?

I guess, kind-of. I never really understood the semantics of `__extension__` though, so I'm not 100% certain.

> I don't think we need to introduce a new attribute to do this, we already have `diagnose_if`. e.g., https://godbolt.org/z/a5ae4T56o would that suffice?

Part of the idea here is that the diagnostics should be part of `-Wc++ab-extension`. I guess we could allow warning flags instead of just `"warning"` and `"error"` in `diagnose_if` that specifies which warning group the diagnostic should be part of. Something like `__attribute__((__diagnose_if__(__cplusplus >= 201703L, "basic_string_view is a C++17 extension", "-Wc++17-extensions")))`. I'm not sure how one could implement that, but I guess there is some mechanism to translate "-Wwhatever" to a warning group, since you can push and pop warnings.  That would open people up to add a diagnostic to pretty much any warning group. I don't know if that's a good idea. I don't really see a problem with that other than people writing weird code, but people do that all the time anyways. Maybe I'm missing something really problematic though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157572



More information about the cfe-commits mailing list