加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 可以将clang格式添加大括号到单行if语句等

发布时间:2020-12-16 02:59:46 所属栏目:百科 来源:网络整理
导读:是否有一个选项为clang格式添加大括号到所有if()/ do / while语句等? 例如 if( i == 42 ) std::cout "You found the meaning of lifen";else std::cout "Wrong!n"; 至 if( i == 42 ){ std::cout "You found the meaning of lifen";}else{ std::cout "Wro
是否有一个选项为clang格式添加大括号到所有if()/ do / while语句等?

例如

if( i == 42 )
   std::cout << "You found the meaning of lifen";
else
   std::cout << "Wrong!n";

if( i == 42 )
{
   std::cout << "You found the meaning of lifen";
}
else
{
   std::cout << "Wrong!n";
}

运用

$clang-format --version
clang-format version 3.6.0

解决方法

clang-tidy可以使用FIXITS对您的代码进行句法更改
clang-tidy YOUR_FILE.cpp -fix -checks="readability-braces-around-statements" -- COMPILE_OPTIONS

更新:

clang-tidy是一个重量级的工具,因为它需要编译选项来解析文件,可悲的是,clang-format(从v3.9开始)不会添加大括号.

COMPILE_OPTIONS将是您用来编译文件的包含路径等,即-std = c 14 -stdlib = libc -O2 -I.

如果您有一个来自CMake的compile_options.json文件,那么您可以将包含的目录的路径传递给clang-tidy,它将查找文件的相应编译选项:

clang-tidy YOUR_FILE.cpp -fix -checks="readability-braces-around-statements" -p COMPILE_OPTIONS_DIR

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读