为什么不使用 static_assert 打印换行符/其他控制序列?
why aren't newlines / other control sequences printed with 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 to\n\n1. Pick up the phone.\n2. Call GhostBusters.\n3. Run and hide.\n\n"
static_assert(false, err);
^ ~~~~~
1 error generated.
有人知道这些是 "unescaped" 的原因吗?它是否依赖于编译器/平台?标准的一部分?
GCC 为您提供所需的换行符:https://godbolt.org/g/jS7Sgm
确切的表示取决于编译器。是否打印转义码可能最好描述为 "quality of implementation" 问题。
标准无外乎:
the resulting diagnostic message (4.1) shall include the text of the string-literal, if one is supplied, except that characters not in the basic source character set (5.3) are not required to appear in the diagnostic message.
换行符是基本源字符集的一部分,因此 "appear" 需要换行符。 它们如何出现与标准控件无关。
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 to\n\n1. Pick up the phone.\n2. Call GhostBusters.\n3. Run and hide.\n\n"
static_assert(false, err);
^ ~~~~~
1 error generated.
有人知道这些是 "unescaped" 的原因吗?它是否依赖于编译器/平台?标准的一部分?
GCC 为您提供所需的换行符:https://godbolt.org/g/jS7Sgm
确切的表示取决于编译器。是否打印转义码可能最好描述为 "quality of implementation" 问题。
标准无外乎:
the resulting diagnostic message (4.1) shall include the text of the string-literal, if one is supplied, except that characters not in the basic source character set (5.3) are not required to appear in the diagnostic message.
换行符是基本源字符集的一部分,因此 "appear" 需要换行符。 它们如何出现与标准控件无关。