7
votes

I use long block C-style Doxygen comments in my C/C++ code. This is style #4 listed on http://www.doxygen.nl/manual/docblocks.html and looks like this (running out to 80 characters)...

/**************************************************************************//**
* \file
* \date   2017-01-02
* \author Alex Hogen
******************************************************************************/

If I run clang-format on this, it inserts a single space between the two forward slashes, so it looks all goofy like this....

/**************************************************************************/ /**
* \file
* \date   2017-01-02
* \author Alex Hogen
******************************************************************************/
  • I have SpacesBeforeTrailingComments set to 2, so that can't be the problem.
  • Tried CommentPragmas regex \/\*+\/\/\*+.
  • Tried CommentPragmas regex /\*(.+\n.+)+\*/
  • I've tried setting ReflowComments to false

... but none of those things have worked.

I understand there are two comments in this block, but I can't find any clang-format parameter addressing block comments on the same line. How can I stop clang-format from inserting this space?

And I don't want to solve this by disabling clang-format for every Doxygen comment block. That seems ridiculous.

Any good suggestions? :-)

1
The more I look at this, the more I'm thinking the solution is to switch from the above format to format #2 (replace two forward slashes at end of first line with one exclamation mark just after the first asterisk on the first line). This would look like a single block comment to clang-format but should still be Doxygen compatible.ahogen
New link for prev comment: Qt style / format #2ahogen

1 Answers

5
votes

In your .clang-format file:

CommentPragmas:  '^\\.+'

This will make it not format comment line that starts with a backslash followed by a word. This works even though there is an asterisk before the doxygen comment because clang-format automatically ignores asterisks and whitespace at the beginning of every comment line.