Skip to content

Commit 052f60d

Browse files
committed
Add a warning about almost-Doxygen trailing comments: //< and /*< ... */
llvm-svn: 159001
1 parent 1fed006 commit 052f60d

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def DeprecatedImplementations :DiagGroup<"deprecated-implementations">;
5757
def : DiagGroup<"disabled-optimization">;
5858
def : DiagGroup<"discard-qual">;
5959
def : DiagGroup<"div-by-zero">;
60+
def Doxygen : DiagGroup<"doxygen">;
6061
def EmptyBody : DiagGroup<"empty-body">;
6162
def ExtraTokens : DiagGroup<"extra-tokens">;
6263

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5665,5 +5665,10 @@ def err_module_private_definition : Error<
56655665
"definition of %0 must be imported before it is required">;
56665666
}
56675667

5668+
let CategoryName = "Documentation Issue" in {
5669+
def warn_not_a_doxygen_trailing_member_comment : Warning<
5670+
"not a Doxygen trailing comment">, InGroup<Doxygen>;
5671+
} // end of documentation issue category
5672+
56685673
} // end of sema component.
56695674

clang/lib/Sema/Sema.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,24 @@ LambdaScopeInfo *Sema::getCurLambda() {
10161016

10171017
void Sema::ActOnComment(SourceRange Comment) {
10181018
RawComment RC(SourceMgr, Comment);
1019+
if (RC.isAlmostTrailingComment()) {
1020+
SourceRange MagicMarkerRange(Comment.getBegin(),
1021+
Comment.getBegin().getLocWithOffset(3));
1022+
StringRef MagicMarkerText;
1023+
switch (RC.getKind()) {
1024+
case RawComment::CK_OrdinaryBCPL:
1025+
MagicMarkerText = "///<";
1026+
break;
1027+
case RawComment::CK_OrdinaryC:
1028+
MagicMarkerText = "/**<";
1029+
break;
1030+
default:
1031+
llvm_unreachable("if this is an almost Doxygen comment, "
1032+
"it should be ordinary");
1033+
}
1034+
Diag(Comment.getBegin(), diag::warn_not_a_doxygen_trailing_member_comment) <<
1035+
FixItHint::CreateReplacement(MagicMarkerRange, MagicMarkerText);
1036+
}
10191037
Context.addComment(RC);
10201038
}
10211039

clang/test/Analysis/retain-release.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ - (OtherRef)_copyOtherRef {
753753
@end
754754

755755
//===----------------------------------------------------------------------===//
756-
//<rdar://problem/6320065> false positive - init method returns an object
756+
// <rdar://problem/6320065> false positive - init method returns an object
757757
// owned by caller
758758
//===----------------------------------------------------------------------===//
759759

clang/test/Sema/doxygen-comments.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
3+
// RUN: cp %s %t
4+
// RUN: %clang_cc1 -fsyntax-only -fixit %t
5+
// RUN: %clang_cc1 -fsyntax-only -Werror %t
6+
7+
struct a {
8+
int x; //< comment // expected-warning {{not a Doxygen trailing comment}}
9+
int y; /*< comment */ // expected-warning {{not a Doxygen trailing comment}}
10+
};
11+
12+
// CHECK: fix-it:"{{.*}}":{8:10-8:13}:"///<"
13+
// CHECK: fix-it:"{{.*}}":{9:10-9:13}:"/**<"
14+

0 commit comments

Comments
 (0)