[clang] b972f2d - [Wdocumentation] Properly place deprecated attribute

Mark de Wever via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 10 12:16:54 PST 2019


Author: Mark de Wever
Date: 2019-12-10T21:16:12+01:00
New Revision: b972f2d05e8b39dd84e586756e7078d79134e2fb

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

LOG: [Wdocumentation] Properly place deprecated attribute

It is now placed before the function:
- allows to replace __attribute__((deprecated)) with [[deprecated]].
- required for trailing returns.

Fixes bug: https://bugs.llvm.org/show_bug.cgi?id=43753

Differential Revision: https://reviews.llvm.org/D71140

Added: 
    

Modified: 
    clang/lib/AST/CommentSema.cpp
    clang/test/Sema/warn-documentation-fixits.cpp
    clang/test/Sema/warn-documentation.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index bef555d3ebe7..d0c98e6de45d 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -701,11 +701,11 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
         AttributeSpelling = MacroName;
     }
 
-    SmallString<64> TextToInsert(" ");
-    TextToInsert += AttributeSpelling;
-    Diag(FD->getEndLoc(), diag::note_add_deprecation_attr)
-        << FixItHint::CreateInsertion(FD->getEndLoc().getLocWithOffset(1),
-                                      TextToInsert);
+    SmallString<64> TextToInsert = AttributeSpelling;
+    TextToInsert += " ";
+    SourceLocation Loc = FD->getSourceRange().getBegin();
+    Diag(Loc, diag::note_add_deprecation_attr)
+        << FixItHint::CreateInsertion(Loc, TextToInsert);
   }
 }
 

diff  --git a/clang/test/Sema/warn-documentation-fixits.cpp b/clang/test/Sema/warn-documentation-fixits.cpp
index 95c0e9350758..1f106a2745b7 100644
--- a/clang/test/Sema/warn-documentation-fixits.cpp
+++ b/clang/test/Sema/warn-documentation-fixits.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -fcomment-block-commands=foobar -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -fcomment-block-commands=foobar -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -fcomment-block-commands=foobar -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -fcomment-block-commands=foobar -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck --check-prefixes=CHECK,CHECK14 %s
 
 // expected-warning at +1 {{parameter 'ZZZZZZZZZZ' not found in the function declaration}} expected-note at +1 {{did you mean 'a'?}}
 /// \param ZZZZZZZZZZ Blah blah.
@@ -51,6 +52,44 @@ struct test_deprecated_6 {
   }
 };
 
+class PR43753 {
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static void test_deprecated_static();
+
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static auto test_deprecated_static_trailing_return() -> int;
+
+#if __cplusplus >= 201402L
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static decltype(auto) test_deprecated_static_decltype_auto() { return 1; }
+#endif
+
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  void test_deprecated_const() const;
+
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  auto test_deprecated_trailing_return() -> int;
+
+#if __cplusplus >= 201402L
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  decltype(auto) test_deprecated_decltype_auto() const { return a; }
+
+private:
+  int a{0};
+#endif
+};
 #define MY_ATTR_DEPRECATED __attribute__((deprecated))
 
 // expected-warning at +1 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}} expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
@@ -76,17 +115,20 @@ int Bar();
 /// \encode PR18051
 int PR18051();
 
-// CHECK: fix-it:"{{.*}}":{5:12-5:22}:"a"
-// CHECK: fix-it:"{{.*}}":{9:12-9:15}:"aaa"
-// CHECK: fix-it:"{{.*}}":{13:13-13:23}:"T"
-// CHECK: fix-it:"{{.*}}":{18:13-18:18}:"SomeTy"
-// CHECK: fix-it:"{{.*}}":{25:25-25:25}:" __attribute__((deprecated))"
-// CHECK: fix-it:"{{.*}}":{29:30-29:30}:" __attribute__((deprecated))"
-// CHECK: fix-it:"{{.*}}":{34:27-34:27}:" __attribute__((deprecated))"
-// CHECK: fix-it:"{{.*}}":{38:27-38:27}:" __attribute__((deprecated))"
-// CHECK: fix-it:"{{.*}}":{46:27-46:27}:" __attribute__((deprecated))"
-// CHECK: fix-it:"{{.*}}":{50:27-50:27}:" __attribute__((deprecated))"
-// CHECK: fix-it:"{{.*}}":{58:30-58:30}:" MY_ATTR_DEPRECATED"
-// CHECK: fix-it:"{{.*}}":{63:6-63:11}:"return"
-// CHECK: fix-it:"{{.*}}":{67:6-67:11}:"foobar"
-// CHECK: fix-it:"{{.*}}":{76:6-76:12}:"endcode"
+// CHECK: fix-it:"{{.*}}":{6:12-6:22}:"a"
+// CHECK: fix-it:"{{.*}}":{10:12-10:15}:"aaa"
+// CHECK: fix-it:"{{.*}}":{14:13-14:23}:"T"
+// CHECK: fix-it:"{{.*}}":{19:13-19:18}:"SomeTy"
+// CHECK: fix-it:"{{.*}}":{26:1-26:1}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{30:1-30:1}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{35:3-35:3}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{39:3-39:3}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{47:3-47:3}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{51:3-51:3}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{76:3-76:3}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{81:3-81:3}:"__attribute__((deprecated)) "
+// CHECK14: fix-it:"{{.*}}":{87:3-87:3}:"__attribute__((deprecated)) "
+// CHECK: fix-it:"{{.*}}":{97:1-97:1}:"MY_ATTR_DEPRECATED "
+// CHECK: fix-it:"{{.*}}":{102:6-102:11}:"return"
+// CHECK: fix-it:"{{.*}}":{106:6-106:11}:"foobar"
+// CHECK: fix-it:"{{.*}}":{115:6-115:12}:"endcode"

diff  --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp
index 3d23acc1bebf..dbd120e6dc85 100644
--- a/clang/test/Sema/warn-documentation.cpp
+++ b/clang/test/Sema/warn-documentation.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -verify %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -Wdocumentation -Wdocumentation-pedantic -verify %s
 
 // This file contains lots of corner cases, so ensure that XML we generate is not invalid.
 // RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s | FileCheck %s -check-prefix=WRONG
@@ -643,6 +644,44 @@ void test_deprecated_6(int a) {
 template<typename T>
 void test_deprecated_7(T aaa);
 
+class PR43753 {
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static void test_deprecated_static();
+
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static auto test_deprecated_static_trailing_return() -> int;
+
+#if __cplusplus >= 201402L
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static decltype(auto) test_deprecated_static_decltype_auto() { return 1; }
+#endif
+
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  void test_deprecated_const() const;
+
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  auto test_deprecated_trailing_return() -> int;
+
+#if __cplusplus >= 201402L
+  // expected-warning at +2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note at +2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  decltype(auto) test_deprecated_decltype_auto() const { return a; }
+
+private:
+  int a{0};
+#endif
+};
 
 // rdar://12397511
 // expected-note at +2 {{previous command '\headerfile' here}}


        


More information about the cfe-commits mailing list