Mordante created this revision. Mordante added reviewers: gribozavr, rsmith. Mordante added a project: clang.
It warns for for comments like /** \pre \em */ where \em has no argument This warning is enabled with the -Wdocumentation option. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D64696 Files: clang/include/clang/Basic/DiagnosticCommentKinds.td clang/lib/AST/CommentParser.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 @@ -1027,6 +1027,49 @@ template<typename T> void test_attach37<T>::test_attach39(int aaa, int bbb) {} +// 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_b(int); + +/// \a A +int test_inline_no_argument_a_g(int); + +// expected-warning@+1 {{'@b' command does not have an argument}} +/// @b +int test_inline_no_argument_b_b(int); + +/// @b A +int test_inline_no_argument_b_g(int); + +// expected-warning@+1 {{'\c' command does not have an argument}} +/// \c +int test_inline_no_argument_c_b(int); + +/// \c A +int test_inline_no_argument_c_g(int); + +// expected-warning@+1 {{'\e' command does not have an argument}} +/// \e +int test_inline_no_argument_e_b(int); + +/// \e A +int test_inline_no_argument_e_g(int); + +// expected-warning@+1 {{'\em' command does not have an argument}} +/// \em +int test_inline_no_argument_em_b(int); + +/// \em A +int test_inline_no_argument_em_g(int); + +// expected-warning@+1 {{'\p' command does not have an argument}} +/// \p +int test_inline_no_argument_p_b(int); + +/// \p A +int test_inline_no_argument_p_g(int); + // We used to emit warning that parameter 'a' is not found because we parsed // the comment in context of the redeclaration which does not have parameter // names. Index: clang/lib/AST/CommentParser.cpp =================================================================== --- clang/lib/AST/CommentParser.cpp +++ clang/lib/AST/CommentParser.cpp @@ -422,6 +422,12 @@ 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(); Index: clang/include/clang/Basic/DiagnosticCommentKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticCommentKinds.td +++ clang/include/clang/Basic/DiagnosticCommentKinds.td @@ -153,6 +153,12 @@ 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<Documentation>, DefaultIgnore; + // verbatim block commands def warn_verbatim_block_end_without_start : Warning<
Index: clang/test/Sema/warn-documentation.cpp =================================================================== --- clang/test/Sema/warn-documentation.cpp +++ clang/test/Sema/warn-documentation.cpp @@ -1027,6 +1027,49 @@ template<typename T> void test_attach37<T>::test_attach39(int aaa, int bbb) {} +// 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_b(int); + +/// \a A +int test_inline_no_argument_a_g(int); + +// expected-warning@+1 {{'@b' command does not have an argument}} +/// @b +int test_inline_no_argument_b_b(int); + +/// @b A +int test_inline_no_argument_b_g(int); + +// expected-warning@+1 {{'\c' command does not have an argument}} +/// \c +int test_inline_no_argument_c_b(int); + +/// \c A +int test_inline_no_argument_c_g(int); + +// expected-warning@+1 {{'\e' command does not have an argument}} +/// \e +int test_inline_no_argument_e_b(int); + +/// \e A +int test_inline_no_argument_e_g(int); + +// expected-warning@+1 {{'\em' command does not have an argument}} +/// \em +int test_inline_no_argument_em_b(int); + +/// \em A +int test_inline_no_argument_em_g(int); + +// expected-warning@+1 {{'\p' command does not have an argument}} +/// \p +int test_inline_no_argument_p_b(int); + +/// \p A +int test_inline_no_argument_p_g(int); + // We used to emit warning that parameter 'a' is not found because we parsed // the comment in context of the redeclaration which does not have parameter // names. Index: clang/lib/AST/CommentParser.cpp =================================================================== --- clang/lib/AST/CommentParser.cpp +++ clang/lib/AST/CommentParser.cpp @@ -422,6 +422,12 @@ 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(); Index: clang/include/clang/Basic/DiagnosticCommentKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticCommentKinds.td +++ clang/include/clang/Basic/DiagnosticCommentKinds.td @@ -153,6 +153,12 @@ 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<Documentation>, DefaultIgnore; + // verbatim block commands def warn_verbatim_block_end_without_start : Warning<
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits