gpt4 book ai didi

c++ - clang 格式在单行上捕获空语句

转载 作者:太空宇宙 更新时间:2023-11-04 12:29:17 25 4
gpt4 key购买 nike

我想知道是否有可能让 clang 格式具有以下异常处理格式。

// Scenario 1: Catch and ignore exception
try
{
DoWork();
}
catch (const SomeException&) {}

// Scenario 2: Handle exception
try
{
DoWork();
}
catch (const SomeException& Exception)
{
// Code handling exception.
}

我无法在单行上获得场景 1 格式,它更喜欢在 { 之前放置一个新行,然后取决于 SplitEmptyFunction 将是:

// Scenario 1: Catch and ignore exception (SplitEmptyFunction is true)
try
{
DoWork();
}
catch (const SomeException&)
{}

// Scenario 1: Catch and ignore exception (SplitEmptyFunction is false)
try
{
DoWork();
}
catch (const SomeException&)
{
}

我是否错过了设置,或者这是不可能的?

最佳答案

目前我的工作是将 SplitEmptyFunction 保持为 false 并应用 post clang 格式 hack 以使用 perl 正则表达式将空捕获更改为在一行上:

  # Hack - allow empty catch statements on a single line.
if ($line =~ /^.+catch.+$/ &&
$lines[$lineNo + 1] =~ /^ +\{ *$/ &&
$lines[$lineNo + 2] =~ /^ +\} *$/)
{
$line = $line." {}";
# Flag following lines when iterated over to be ignored.
$lines[$lineNo + 1] = "clang_format_no_op_entire_statement";
$lines[$lineNo + 2] = "clang_format_no_op_entire_statement";
}

关于c++ - clang 格式在单行上捕获空语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59295462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com