Skip to content

Instantly share code, notes, and snippets.

@clemensg
Created November 29, 2017 10:13
Show Gist options
  • Save clemensg/7665cec5a020680cffa06bfcad6fc809 to your computer and use it in GitHub Desktop.
Save clemensg/7665cec5a020680cffa06bfcad6fc809 to your computer and use it in GitHub Desktop.
Bug 34649 - clang-format messes up comment indentations - Problem 2
void main(void)
{
int a = 1;
/* FOO begins */
#ifndef FOO
if (a)
{
return;
}
#endif
/* FOO ends */
}
@clemensg
Copy link
Author

clang-format 9.0.0 changes it to:

void main(void)
{
  int a = 1;

/* FOO begins */
#ifndef FOO
  if (a)
  {
    return;
  }
#endif
  /* FOO ends */
}

I think it should stay as it was, instead..


Usecase for these comments at the beginning and end of very long ifdef blocks is to tell the reader what the ifdef was about.
Example:

/* Ticket 1234 */
#ifdef
  /* ... */
#endif
/* Ticket 1234 */

I personally don't use this style (I'd rather add the comment in the line of the endif or just in the git commit message) but we have a large legacy codebase with thousands of such comments we'd like to reformat but can't because this kind of comment indentation makes it even less readable than it is right now.

.clang-format being used is https://gist.github.com/clemensg/be1dc3f2c4442a995cba3d8068917848

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment