我的代码中有一些注释:

//asdf

当我在上面使用clang-format时,它会在//字符之后添加一个空格:
// asdf

如何防止这种情况在 clang-format 配置中发生?

谢谢

最佳答案

结合这两个问题的答案可以解决问题:

  • clang-format breaks lint annotations
  • What regex will match every character except comma ',' or semi-colon ';'?

  • 因此,您的.clang-format文件中的以下行应该可以解决问题(我没有对其进行测试):
    CommentPragmas:  '^[^ ]'
    

    这告诉 clang-format 不要弄乱以空格开头的注释。

    For completeness, clang-format documentation here

    关于c++ - 如何防止 clang-format 在注释字符后添加空间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32970045/

    10-10 23:36
    查看更多