The assertion happens when compiling with -Wdocumentation with variable declaration to a typedefed function pointer. I not too familiar with the ObjC syntax but first two tests assert without this patch.
Details
Diff Detail
Event Timeline
clang/lib/AST/Comment.cpp | ||
---|---|---|
151 | Why is the new functionality turned off sometimes? It seems to me that we always want to look through typedefs. |
clang/lib/AST/Comment.cpp | ||
---|---|---|
151 | Setting testTypedefTypeLoc to true breaks a unit test in test/Sema/warn-documentation.cpp:358 typedef int (*test_not_function_like_typedef1)(int aaa); // expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}} /// \param aaa Meow. typedef test_not_function_like_typedef1 test_not_function_like_typedef2; and its corresponding test using a using instead of typedef. This has been introduced in: commit 49fdf8d3f5e114e6f8b49fde29a30b0eaaa3c5dd Author: Dmitri Gribenko <gribozavr@gmail.com> Date: Sat Sep 15 21:13:36 2012 +0000 Comment parsing: don't treat typedef to a typedef to a function as a 'function-like' type that can be annotated with \param. Thanks to Eli Friedman for noticing! llvm-svn: 163985 I'm not sure whether or not we should allow this typedef documentation. I just tested with Doxygen. It doesn't complain and shows the parameter documentation for test_not_function_like_typedef2. So on that basis we could remove this expected-warning and testTypedefTypeLoc. What do you think? |
clang/lib/AST/Comment.cpp | ||
---|---|---|
151 | Thanks for the explanation. I can't find the context for that decision, and the commit description does not explain the reason either. It is really a policy decision -- when introducing a comment for function return value and arguments, should the declaration include the said return value and arguments, or can they be visible through a typedef? Thinking about it, my inclination is to say that comments for the return value and arguments should be present on the declaration that introduces them. Otherwise, it is breaking an abstraction barrier. WDYT? |
clang/lib/AST/Comment.cpp | ||
---|---|---|
151 | (I just noticed I forgot to submit this comment.) I tend to agree. However Doxygen accepts the code, but Doxygen doesn't seem to validate whether parameters exist. We could add an extra warning in the pedantic group and let the user decide whether or not she thinks it warrants a warning. I think that would be the best solution: accept the comment but allow the user to opt-in on a warning. |
clang/lib/AST/Comment.cpp | ||
---|---|---|
151 | Doxygen and C++ both allow a lot of dubious stuff. That can't be a reason to avoid producing a warning -- we would have no warnings if that was the bar. I think what we should discuss is, what is the use case for adding a \returns command in this position -- and how is documenting parameters not a use case. If there is a valid use case, how common it is in real world. |
As discussed on IRC no longer allow \return on a typedef'ed type. This is consistent with \param.
- Reverts all prior changes in lib/AST/Comment.cpp
- Adds extra tests in Sema::isFunctionOrBlockPointerVarLikeDecl
- Updates unit tests
LGTM, but could you also verify that references are not an issue?
using D = void(); D &d = ...; ///< \return none
Thanks for the review.
using D = void(); D &d = ...; ///< \return none
Is no issue, I added tests for it.
Can you commit the code for me?
Why is the new functionality turned off sometimes? It seems to me that we always want to look through typedefs.