【问题标题】:clang-format malforming comment blocksclang 格式畸形的评论块
【发布时间】:2020-07-12 15:47:49
【问题描述】:

快速提问:

我有一些code 看起来像:

if (interactive)
    ret = main_interactive(ctx, debug, use_aio);
else
    ret = main_server(ctx, debug);

/*
 * In case we got here through an error in the main thread make sure all
 * the worker threads are signaled to shutdown.
 */

当我通过 clang-format 7.0.1-8 (debian) 运行它时(使用这个 .clang-format 文件),我得到 this

if (interactive)
    ret = main_interactive(ctx, debug, use_aio);
else
    ret = main_server(ctx, debug);

    /*
 * In case we got here through an error in the main thread make sure all
 * the worker threads are signaled to shutdown.
 */

可以看到注释块的第一行缩进不正确。

有什么建议吗?

【问题讨论】:

  • 我无法重现您的错误。如果您使用不同的系统和配置文件,您不太可能会看到此问题。
  • 我能够使用相同的配置文件在不同的系统上重现它。我不仅使用了 sn-p,还使用了整个文件,以防文件顶部的某些内容混淆了 clang-format。

标签: clang-format


【解决方案1】:

我已经在 CLion 2020.RC1 中尝试过你的 clang-format 配置,问题似乎是评论的第一行 (/*) 缩进了制表符(每个配置有 8 个空格),而其余的的注释行缩进 4 个空格。
以下是您在 CLion 中使用“show whitespace: on”的代码:

这可以通过选项ReflowComments: true 修复。这样所有评论的行都将使用制表符缩进。

【讨论】:

  • 谢谢 - 这确实缩进(排列 cmets),但它与缩进的 ret = main ... 对齐,而不是一个后面(应该是流的位置。周围没有 {} else,注释是下一段代码的头部,和前面的if/else....没有任何关系。
猜你喜欢
  • 2016-07-17
  • 2019-03-30
  • 1970-01-01
  • 1970-01-01
  • 2016-05-20
  • 2020-06-30
  • 2018-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多