【问题标题】:Does clang code formatting utility break defines only on Windows?clang 代码格式化实用程序是否仅在 Windows 上定义?
【发布时间】:2013-09-11 04:52:56
【问题描述】:

对于支持代码格式化的 VS,有一个不错的 clang plugin。这很好,但它打破了所有复杂的定义:

假设我们有:

#include <boost/preprocessor.hpp>
#include <boost/shared_ptr.hpp>

#define NM_PP_VARIADIC_MAX_LENGTH 5

#define NM_PP_TYPE_DECL(z, n, T) \
class BOOST_PP_CAT(T, n )

#define NM_PP_TYPE(z, n, T) \
    BOOST_PP_CAT(T, n )

#define NM_PP_ARGUMENT_DECL(z, n, T) \
    BOOST_PP_CAT(T, n ) BOOST_PP_CAT(t, n )

这是我们格式化后得到的:

#include <boost/preprocessor.hpp>
#include <boost/shared_ptr.hpp>

#define NM_PP_VARIADIC_MAX_LENGTH 5

#define NM_PP_TYPE_DECL(z, n, T) \
class BOOST_PP_CAT(T, n)

#define NM_PP_TYPE(z, n, T)
BOOST_PP_CAT(T, n)

#define NM_PP_ARGUMENT_DECL(z, n, T)
BOOST_PP_CAT(T, n) BOOST_PP_CAT(t, n)

如您所见,此类代码将无法编译,并且大多数 \ 已被删除。有没有办法将其配置为不删除\

我尝试使用 LLVM 之类的默认配置并查看了 formatting arguments,但我看不出这种残酷的代码优化是在哪里定义的。

【问题讨论】:

    标签: c++ visual-studio visual-studio-2012 clang clang-format


    【解决方案1】:

    我会说这是由使用的文件结尾引起的,通常是 Windows 中的 CR+LF。尝试将您的文件转换为 unix 样式的行尾 (LF),它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-30
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-28
      相关资源
      最近更新 更多