在C++合约的简单使用中,我得到了error: no type named 'fail_fast' in namespace 'gsl'
。try块会抛出fast_fail
异常还是其他异常?
#define GSL_THROW_ON_CONTRACT_VIOLATION
#include <gsl/gsl>
#include <iostream>
int main(void)
{
try {
Expects(false);
}
catch(const gsl::fail_fast &e) {
std::cout << "exception: " << e.what() << 'n';
}
}
GSL_THROW_ON_CONTRACT_VIOLATION
和gsl::fast_fail
从Microsoft GSL 3.0.0版开始删除。所有违反约定的行为都会导致对std::terminate
的调用,除非您是在MSVC的内核模式下构建的,它会调用__fastfail
。
头文件gsl_assert.h仅定义gsl::fail_fast异常,并定义了gsl_THROW_ON_CONTRACT_VIOLATION。所以它现在就编译了服务Laurijssen
有一段时间,只有在定义GSL_THROW_ON_CONTRACT_VIOLATION
时才定义gsl::fast_fail
,但它在#267中被识别,随后在#268中被固定。