aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-11-18 00:30:31 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-11-18 00:30:31 +0000
commit36cbbe916f66f08d36492e75809fbf54416a5e8d (patch)
treed13331699325b3e99a00f73bb5c1a9ad5f6587c4
parentd9ffa0c39ff9c71e2729eac4cdcf32b377c1d3b6 (diff)
Documentation parsing: propely handle a lone '\endverbatim' and emit a warning.
We actually used to assert on this. Thanks to NAKAMURA Takumi for noticing this! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168277 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticCommentKinds.td6
-rw-r--r--lib/AST/CommentParser.cpp8
-rw-r--r--test/Sema/warn-documentation.cpp18
3 files changed, 32 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticCommentKinds.td b/include/clang/Basic/DiagnosticCommentKinds.td
index 7203ac75f8..e6dfe5b638 100644
--- a/include/clang/Basic/DiagnosticCommentKinds.td
+++ b/include/clang/Basic/DiagnosticCommentKinds.td
@@ -131,5 +131,11 @@ def warn_doc_deprecated_not_sync : Warning<
def note_add_deprecation_attr : Note<
"add a deprecation attribute to the declaration to silence this warning">;
+// verbatim block commands
+
+def warn_verbatim_block_end_without_start : Warning<
+ "'\\%0' command does not terminate a verbatim text block">,
+ InGroup<Documentation>, DefaultIgnore;
+
} // end of documentation issue category
} // end of AST component
diff --git a/lib/AST/CommentParser.cpp b/lib/AST/CommentParser.cpp
index d053dc0f18..d0a84741b6 100644
--- a/lib/AST/CommentParser.cpp
+++ b/lib/AST/CommentParser.cpp
@@ -554,6 +554,14 @@ BlockContentComment *Parser::parseParagraphOrBlockCommand() {
return parseBlockCommand();
break; // Block command ahead, finish this parapgaph.
}
+ if (Info->IsVerbatimBlockEndCommand) {
+ Diag(Tok.getLocation(),
+ diag::warn_verbatim_block_end_without_start)
+ << Info->Name
+ << SourceRange(Tok.getLocation(), Tok.getEndLocation());
+ consumeToken();
+ continue;
+ }
if (Info->IsUnknownCommand) {
Content.push_back(S.actOnUnknownCommand(Tok.getLocation(),
Tok.getEndLocation(),
diff --git a/test/Sema/warn-documentation.cpp b/test/Sema/warn-documentation.cpp
index b5d3300efd..3eca3c8dc1 100644
--- a/test/Sema/warn-documentation.cpp
+++ b/test/Sema/warn-documentation.cpp
@@ -502,6 +502,24 @@ enum test_returns_wrong_decl_8 {
namespace test_returns_wrong_decl_10 { };
+// expected-warning@+1 {{'\endverbatim' command does not terminate a verbatim text block}}
+/// \endverbatim
+int test_verbatim_1();
+
+// expected-warning@+1 {{'\endcode' command does not terminate a verbatim text block}}
+/// \endcode
+int test_verbatim_2();
+
+// FIXME: we give a bad diagnostic here because we throw away non-documentation
+// comments early.
+//
+// expected-warning@+2 {{'\endcode' command does not terminate a verbatim text block}}
+/// \code
+// foo
+/// \endcode
+int test_verbatim_3();
+
+
// expected-warning@+1 {{empty paragraph passed to '\brief' command}}
int test1; ///< \brief\author Aaa