Regression in -Wdocumentation behavior with typedef struct
| Bugzilla Link | 44143 |
| Resolution | FIXED |
| Resolved on | Jun 02, 2020 16:20 |
| Version | trunk |
| OS | All |
| Reporter | LLVM Bugzilla Contributor |
| CC | @jkorous-apple,@karka228,@zygoloid |
Extended Description
The following code triggers a false positive warning when compiled with -Wdocumentation:
/**
* @​struct MyStruct
* @​brief Some blurb
*
* More details here. Doesn't matter what.
*/
typedef struct MyStruct
{
int type;
int pid;
int msgPrio;
} MyStruct;
The warning generated is:
$ ./bin/clang -c -Wdocumentation foo.c
foo.c:2:5: warning: '@struct' command should not be used in a comment attached to a non-struct declaration [-Wdocumentation]
* @​struct MyStruct
~^~~~~~~~~~~~~~~
1 warning generated.
Separating the struct declaration from the typedef, as follows, avoids the warning:
/**
* @​struct MyStruct
* @​brief Some blurb
*
* More details here. Doesn't matter what.
*/
struct MyStruct
{
int type;
int pid;
int msgPrio;
};
typedef struct MyStruct MyStruct;
This behavior changed about a week ago. (Not exactly sure which commit-- haven't narrowed that down.)
Ahhh, thanks!
This issue is fixed by commit 2f56789c8fe8e (https://reviews.llvm.org/D74746).
We parse doxygen comments and the function I linked is the only place where I found the specific warning produced.
AFAIK the comment parsing takes place in RawComment::parse(). https://clang.llvm.org/doxygen/classclang_1_1RawComment.html#afba3d7f58101886ff86e1bce47521f48
It seems that the check that now produces incorrect warning just expects comment being attached to a struct if there's @struct doxygen command used.
That's my understanding of current behavior. I might take a look later unless you or Sam beat me.
Jan, I don't have a good understanding of this code yet. The code you linked to is code I looked at when trying to root-cause this issue, but it wasn't clear to me what needed to change or exactly where. If you have a clearer understanding of what the fix needs to be, could you provide a bit more detail? I'd be happy to implement and test the fix.
I'll also ping @sammccall on the clang bug related to the original change that caused this regression.
Since we now attach comment related to a struct to its typedef, the context in which doxygen is parsed is different.
We should probably update this check to account for the change: https://github.com/llvm/llvm-project/blob/master/clang/lib/AST/CommentSema.cpp#L130 Sema::checkContainerDeclVerbatimLine
Demonstration of incorrect behavior... https://godbolt.org/z/RGvkCm
Commit that caused this issue was a433e7141fb3f697e6430437ee73b19076603c1b, reviewed in https://reviews.llvm.org/D70203.