希望这个问题不会太愚蠢。我是一个使用gtest的新手,我已经很长时间没有使用C++了。假设w有这个简单的模板Point类:
template <class T>
struct Point
{
union
{
T _data [2];
struct { T x, y; };
};
constexpr Point(T x_, T y_) noexcept : x(x_), y(x_) {}
};然后使用gtest,我尝试检查Point是否是默认可构造的:
TEST_P(PointTest,Concept)
{
ASSERT_TRUE(std::is_nothrow_constructible<Point<float>,float,float>::value);
}然后我在带有C++11标志的Clang 6.0.1中得到了这个编译错误:
"error: too many arguments provided to function-like macro invocation"任何帮助都将受到欢迎。我知道在组合模板和googletest时必须特别小心。但是我没有想出一个解决方案。谢谢!
发布于 2018-08-13 20:54:04
我认为这是C++预处理器在识别模板参数之间的逗号时出现的问题
// ...................................................v.....v
ASSERT_TRUE(std::is_nothrow_constructible<Point<float>,float,float>::value);作为宏参数分隔符。
我建议在宏调用外部计算值。
TEST_P(PointTest,Concept)
{
constexpr auto val
= std::is_nothrow_constructible<Point<float>, float, float>::value;
ASSERT_TRUE( val );
}或通过类型的using传递
TEST_P(PointTest ,Concept)
{
using inc = std::is_nothrow_constructible<Point<float>, float, float>;
ASSERT_TRUE( inc::value );
}https://stackoverflow.com/questions/51818382
复制相似问题