From: Dmitri Gribenko Date: Fri, 22 Jun 2012 16:02:55 +0000 (+0000) Subject: Add a warning about almost-Doxygen trailing comments: //< and /*< ... */ X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9dda4746867a747c1c3421d8a04a1b666aeb5809;p=clang Add a warning about almost-Doxygen trailing comments: //< and /*< ... */ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159001 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 978e951acf..0b46c8a8ba 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -57,6 +57,7 @@ def DeprecatedImplementations :DiagGroup<"deprecated-implementations">; def : DiagGroup<"disabled-optimization">; def : DiagGroup<"discard-qual">; def : DiagGroup<"div-by-zero">; +def Doxygen : DiagGroup<"doxygen">; def EmptyBody : DiagGroup<"empty-body">; def ExtraTokens : DiagGroup<"extra-tokens">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 43ef9aca58..a8150b73b9 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -5665,5 +5665,10 @@ def err_module_private_definition : Error< "definition of %0 must be imported before it is required">; } +let CategoryName = "Documentation Issue" in { +def warn_not_a_doxygen_trailing_member_comment : Warning< + "not a Doxygen trailing comment">, InGroup; +} // end of documentation issue category + } // end of sema component. diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 9e4b291971..9d18a5c596 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -1016,6 +1016,24 @@ LambdaScopeInfo *Sema::getCurLambda() { void Sema::ActOnComment(SourceRange Comment) { RawComment RC(SourceMgr, Comment); + if (RC.isAlmostTrailingComment()) { + SourceRange MagicMarkerRange(Comment.getBegin(), + Comment.getBegin().getLocWithOffset(3)); + StringRef MagicMarkerText; + switch (RC.getKind()) { + case RawComment::CK_OrdinaryBCPL: + MagicMarkerText = "///<"; + break; + case RawComment::CK_OrdinaryC: + MagicMarkerText = "/**<"; + break; + default: + llvm_unreachable("if this is an almost Doxygen comment, " + "it should be ordinary"); + } + Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment) << + FixItHint::CreateReplacement(MagicMarkerRange, MagicMarkerText); + } Context.addComment(RC); } diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index cda60b1420..87e09e9a83 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -753,7 +753,7 @@ typedef CFTypeRef OtherRef; @end //===----------------------------------------------------------------------===// -// false positive - init method returns an object +// false positive - init method returns an object // owned by caller //===----------------------------------------------------------------------===// diff --git a/test/Sema/doxygen-comments.c b/test/Sema/doxygen-comments.c new file mode 100644 index 0000000000..d2b0daecb8 --- /dev/null +++ b/test/Sema/doxygen-comments.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s +// RUN: cp %s %t +// RUN: %clang_cc1 -fsyntax-only -fixit %t +// RUN: %clang_cc1 -fsyntax-only -Werror %t + +struct a { + int x; //< comment // expected-warning {{not a Doxygen trailing comment}} + int y; /*< comment */ // expected-warning {{not a Doxygen trailing comment}} +}; + +// CHECK: fix-it:"{{.*}}":{8:10-8:13}:"///<" +// CHECK: fix-it:"{{.*}}":{9:10-9:13}:"/**<" +