Mordante created this revision.
Mordante added a reviewer: gribozavr2.
Mordante added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71140

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

Index: clang/test/Sema/warn-documentation.cpp
===================================================================
--- clang/test/Sema/warn-documentation.cpp
+++ 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 @@
 template<typename T>
 void test_deprecated_7(T aaa);
 
+class PR43753 {
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static void test_deprecated_static();
+
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+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@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+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@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  void test_deprecated_const() const;
+
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  auto test_deprecated_trailing_return() -> int;
+
+#if __cplusplus >= 201402L
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+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@+2 {{previous command '\headerfile' here}}
Index: clang/test/Sema/warn-documentation-fixits.cpp
===================================================================
--- clang/test/Sema/warn-documentation-fixits.cpp
+++ 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@+1 {{parameter 'ZZZZZZZZZZ' not found in the function declaration}} expected-note@+1 {{did you mean 'a'?}}
 /// \param ZZZZZZZZZZ Blah blah.
@@ -51,6 +52,44 @@
   }
 };
 
+class PR43753 {
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  static void test_deprecated_static();
+
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+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@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+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@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  void test_deprecated_const() const;
+
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+2 {{add a deprecation attribute to the declaration to silence this warning}}
+  /// \deprecated
+  auto test_deprecated_trailing_return() -> int;
+
+#if __cplusplus >= 201402L
+  // expected-warning@+2 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}}
+  // expected-note@+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@+1 {{declaration is marked with '\deprecated' command but does not have a deprecation attribute}} expected-note@+2 {{add a deprecation attribute to the declaration to silence this warning}}
@@ -76,17 +115,20 @@
 /// \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"
Index: clang/lib/AST/CommentSema.cpp
===================================================================
--- clang/lib/AST/CommentSema.cpp
+++ clang/lib/AST/CommentSema.cpp
@@ -701,11 +701,11 @@
         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);
   }
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to