[PATCH] D113115: Add diagnostic groups for attribute extensions

2021-12-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

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



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113115

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113115: Add diagnostic groups for attribute extensions

2021-11-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D113115#3106360 , @erichkeane 
wrote:

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


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113115

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113115: Add diagnostic groups for attribute extensions

2021-11-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

I like the approach, and a pretty trivial implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113115

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113115: Add diagnostic groups for attribute extensions

2021-11-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, rjmccall, jyknight, erichkeane.
aaron.ballman requested review of this revision.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113115

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/test/SemaCXX/attr-extension-diags.cpp


Index: clang/test/SemaCXX/attr-extension-diags.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/attr-extension-diags.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++11 -verify=ext -fsyntax-only 
-Wfuture-attribute-extensions %s
+// RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only 
-Wno-future-attribute-extensions %s
+// RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only 
-Wno-c++14-attribute-extensions -Wno-c++17-attribute-extensions 
-Wno-c++20-attribute-extensions %s
+
+// expected-no-diagnostics
+
+[[deprecated]] int func1(); // ext-warning {{use of the 'deprecated' attribute 
is a C++14 extension}}
+[[deprecated("msg")]] int func2(); // ext-warning {{use of the 'deprecated' 
attribute is a C++14 extension}}
+
+[[nodiscard]] int func3(); // ext-warning {{use of the 'nodiscard' attribute 
is a C++17 extension}}
+[[nodiscard("msg")]] int func4(); // ext-warning {{use of the 'nodiscard' 
attribute is a C++20 extension}}
+
+void func5() {
+  if (true) [[likely]]; // ext-warning {{use of the 'likely' attribute is a 
C++20 extension}}  
+}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8617,11 +8617,11 @@
   InGroup>;
 
 def ext_cxx14_attr : Extension<
-  "use of the %0 attribute is a C++14 extension">, InGroup;
+  "use of the %0 attribute is a C++14 extension">, InGroup;
 def ext_cxx17_attr : Extension<
-  "use of the %0 attribute is a C++17 extension">, InGroup;
+  "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
-  "use of the %0 attribute is a C++20 extension">, InGroup;
+  "use of the %0 attribute is a C++20 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1040,6 +1040,13 @@
 def NonGCC : DiagGroup<"non-gcc",
 [SignCompare, Conversion, LiteralRange]>;
 
+def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
+def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
+def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
+CXX17Attrs,
+CXX20Attrs]>;
+
 // A warning group for warnings about using C++11 features as extensions in
 // earlier C++ versions.
 def CXX11 : DiagGroup<"c++11-extensions", [CXX11ExtraSemi, 
CXX11InlineNamespace,
@@ -1047,15 +1054,15 @@
 
 // A warning group for warnings about using C++14 features as extensions in
 // earlier C++ versions.
-def CXX14 : DiagGroup<"c++14-extensions", [CXX14BinaryLiteral]>;
+def CXX14 : DiagGroup<"c++14-extensions", [CXX14BinaryLiteral, CXX14Attrs]>;
 
 // A warning group for warnings about using C++17 features as extensions in
 // earlier C++ versions.
-def CXX17 : DiagGroup<"c++17-extensions">;
+def CXX17 : DiagGroup<"c++17-extensions",