modernize-use-uncaught-exceptions¶
此检查会对调用 std::uncaught_exception
发出警告,并将它们替换为调用 std::uncaught_exceptions
,因为 std::uncaught_exception
在 C++17 中已被弃用。
以下是将找到哪些类型的出现以及将用什么替换它们的几个示例。
#define MACRO1 std::uncaught_exception
#define MACRO2 std::uncaught_exception
int uncaught_exception() {
return 0;
}
int main() {
int res;
res = uncaught_exception();
// No warning, since it is not the deprecated function from namespace std
res = MACRO2();
// Warning, but will not be replaced
res = std::uncaught_exception();
// Warning and replaced
using std::uncaught_exception;
// Warning and replaced
res = uncaught_exception();
// Warning and replaced
}
应用修复后,代码将如下所示
#define MACRO1 std::uncaught_exception
#define MACRO2 std::uncaught_exception
int uncaught_exception() {
return 0;
}
int main() {
int res;
res = uncaught_exception();
res = MACRO2();
res = std::uncaught_exceptions();
using std::uncaught_exceptions;
res = uncaught_exceptions();
}