From 657330ee0e41b90fa7f7b55fb7caa11f9c2c5369 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Mon, 5 Aug 2019 08:05:16 +0000 Subject: [PATCH] Adds a warning when an inline Doxygen comment has no argument Summary: It warns for for comments like /** \pre \em */ where \em has no argument This warning is enabled with the -Wdocumentation option. Reviewers: gribozavr, rsmith Reviewed By: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64696 Patch by Mark de Wever. llvm-svn: 367809 --- .../include/clang/Basic/DiagnosticCommentKinds.td | 6 ++++ clang/lib/AST/CommentParser.cpp | 6 ++++ clang/test/Sema/warn-documentation.cpp | 42 ++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/clang/include/clang/Basic/DiagnosticCommentKinds.td b/clang/include/clang/Basic/DiagnosticCommentKinds.td index fcda3f3..d8ce258 100644 --- a/clang/include/clang/Basic/DiagnosticCommentKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommentKinds.td @@ -153,6 +153,12 @@ def warn_doc_deprecated_not_sync : Warning< def note_add_deprecation_attr : Note< "add a deprecation attribute to the declaration to silence this warning">; +// inline contents commands + +def warn_doc_inline_contents_no_argument : Warning< + "'%select{\\|@}0%1' command does not have an argument">, + InGroup, DefaultIgnore; + // verbatim block commands def warn_verbatim_block_end_without_start : Warning< diff --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp index c7f8aa7..29983b0 100644 --- a/clang/lib/AST/CommentParser.cpp +++ b/clang/lib/AST/CommentParser.cpp @@ -422,6 +422,12 @@ InlineCommandComment *Parser::parseInlineCommand() { IC = S.actOnInlineCommand(CommandTok.getLocation(), CommandTok.getEndLocation(), CommandTok.getCommandID()); + + Diag(CommandTok.getEndLocation().getLocWithOffset(1), + diag::warn_doc_inline_contents_no_argument) + << CommandTok.is(tok::at_command) + << Traits.getCommandInfo(CommandTok.getCommandID())->Name + << SourceRange(CommandTok.getLocation(), CommandTok.getEndLocation()); } Retokenizer.putBackLeftoverTokens(); diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp index 5083f68..df7e189 100644 --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -1044,6 +1044,48 @@ template <> template void test_attach38::test_attach39(int, B); +// The inline comments expect a string after the command. +// expected-warning@+1 {{'\a' command does not have an argument}} +/// \a +int test_inline_no_argument_a_bad(int); + +/// \a A +int test_inline_no_argument_a_good(int); + +// expected-warning@+1 {{'@b' command does not have an argument}} +/// @b +int test_inline_no_argument_b_bad(int); + +/// @b A +int test_inline_no_argument_b_good(int); + +// expected-warning@+1 {{'\c' command does not have an argument}} +/// \c +int test_inline_no_argument_c_bad(int); + +/// \c A +int test_inline_no_argument_c_good(int); + +// expected-warning@+1 {{'\e' command does not have an argument}} +/// \e +int test_inline_no_argument_e_bad(int); + +/// \e A +int test_inline_no_argument_e_good(int); + +// expected-warning@+1 {{'\em' command does not have an argument}} +/// \em +int test_inline_no_argument_em_bad(int); + +/// \em A +int test_inline_no_argument_em_good(int); + +// expected-warning@+1 {{'\p' command does not have an argument}} +/// \p +int test_inline_no_argument_p_bad(int); + +/// \p A +int test_inline_no_argument_p_good(int); // PR13411, reduced. We used to crash on this. /** -- 2.7.4