为什么换行符/其他控制序列不打印static_assert?


int main(int argc, char **argv) {
    static_assert(false, R"error(This is an error message.  You need to
1. Pick up the phone.
2. Call GhostBusters.
3. Run and hide.
)error");
}

给出

error: static_assert failed "This is an error message. You need tonn1. Pick up the phone.n2. Call GhostBusters.n3. Run and hide.nn"
    static_assert(false, err);
    ^             ~~~~~
1 error generated.

有人知道这些是"不渗透"的原因吗?它是否取决于编译器/平台?标准的一部分?

标准所说的不过是:

由此产生的诊断消息(4.1)应包括字符串文字(如果提供的话),除非不需要在诊断消息中出现基本源字符集(5.3)中的字符。/blockquote>

newlines是基本源字符集的一部分,因此需要"出现"。它们看起来并不是标准控件。

gcc为您提供所需的新线:https://godbolt.org/g/js7sgm

确切的呈现取决于编译器。打印逃生代码是否可以最好地描述为"实施质量"问题。

最新更新