GoogleTest with Templates

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



GoogleTest with Templates



Hope this question will not be too stupid. I'm quite new in using gtest and it's been quite a very long time that I don't make use of C++.
Let suppose w have this simplistic template Point class:


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_)
;



Then using gtest, I'm trying to check if Point is default constructible:


Point


TEST_P(PointTest,Concept)

ASSERT_TRUE(std::is_nothrow_constructible<Point<float>,float,float>::value);



Then I get this compilation error with Clang 6.0.1 with C++11 flags:


"error: too many arguments provided to function-like macro invocation"



Any help will be welcome. I do know that special care must be taken when combining templates and googletest. But I didn't figure out a solution.
Thank you !




1 Answer
1



I suppose it's a problem with C++ preprocessor that recognize the commas between templates arguments


// ...................................................v.....v
ASSERT_TRUE(std::is_nothrow_constructible<Point<float>,float,float>::value);



as macros arguments separators.



I suggest to calculate the value outside the macro call


TEST_P(PointTest,Concept)

constexpr auto val
= std::is_nothrow_constructible<Point<float>, float, float>::value;

ASSERT_TRUE( val );



or to pass through a using for the type


using


TEST_P(PointTest ,Concept)

using inc = std::is_nothrow_constructible<Point<float>, float, float>;

ASSERT_TRUE( inc::value );





Many thanks, @max66! Your suggestion solves my problem.
– Cherubin
Aug 13 at 12:59






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard