This is an archive of the discontinued LLVM Phabricator instance.

Add diagnostic groups for attribute extensions
ClosedPublic

Authored by aaron.ballman on Nov 3 2021, 8:42 AM.

Details

Summary

Some users have a need to control attribute extension diagnostics independent of other extension diagnostics. Consider something like use of [[nodiscard]] within C++11:

#if __has_cpp_attribute(nodiscard)
[[nodiscard]] 
#endif
int f();

If compiled with -Wc++17-extensions enabled, this will produce warning: use of the 'nodiscard' attribute is a C++17 extension. This diagnostic is correct -- using [[nodiscard]] in C++11 mode is a C++17 extension. And the behavior of __has_cpp_attribute(nodiscard) is also correct -- we support [[nodiscard]] in C++11 mode as a conforming extension. But this makes use of -Werror or -pedantic-errors` builds more onerous.

This patch adds diagnostic groups for attribute extensions so that users can selectively disable attribute extension diagnostics. I believe this is preferable to requiring users to specify additional flags because it means -Wc++17-extensions continues to be the way we enable all C++17-related extension diagnostics. It would be quite easy for someone to use that flag thinking they're protected from some portability issues without realizing it skipped attribute extensions if we went the other way.

This addresses PR33518.

Diff Detail

Event Timeline

aaron.ballman requested review of this revision.Nov 3 2021, 8:42 AM
aaron.ballman created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2021, 8:42 AM
erichkeane accepted this revision.Nov 3 2021, 8:50 AM

I like the approach, and a pretty trivial implementation.

This revision is now accepted and ready to land.Nov 3 2021, 8:50 AM

I like the approach, and a pretty trivial implementation.

Thanks for the review! I'm going to hold off on landing for a little bit in case @rsmith has opinions because he had other ideas on the bug report itself.

aaron.ballman closed this revision.Dec 7 2021, 8:50 AM

I've committed (with a release note) in a18632adc884397e0cd7f27bdb8ea3a822b63000