-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler problem with operator and include catch_all.hpp #2792
Comments
The error can be reproduced, #include <catch2/catch_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark_all.hpp>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_assertion_info.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/catch_config.hpp>
#include <catch2/catch_get_random_seed.hpp>
#include <catch2/catch_message.hpp>
#include <catch2/catch_section_info.hpp>
#include <catch2/catch_session.hpp>
#include <catch2/catch_tag_alias.hpp>
#include <catch2/catch_tag_alias_autoregistrar.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_case_info.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_test_spec.hpp>
#include <catch2/catch_timer.hpp>
#include <catch2/catch_tostring.hpp>
#include <catch2/catch_totals.hpp>
#include <catch2/catch_translate_exception.hpp>
#include <catch2/catch_version.hpp>
#include <catch2/catch_version_macros.hpp>
// #include <catch2/generators/catch_generators_all.hpp>
#include <catch2/generators/catch_generator_exception.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/generators/catch_generators_adapters.hpp>
// adding this include creates this error
#include <catch2/generators/catch_generators_random.hpp>
#include <catch2/generators/catch_generators_range.hpp>
TEST_CASE("first") {
REQUIRE(true);
//REQUIRE(5 <= 5);
} In the combination of the above includes (as they are from catch_all) the error can be "tuned on / off" by include catch_generators_random.hpp Catch version: v3.5.0 |
Can you reproduce this with a newer version of Visual Studio or does it only appear with VS 2017? |
I'v just tried VS 2017 till now. But with the new Catch version: v3.5.2 I've get the Error C2039 also in the SelfTest of TEST_CASE("Comparison ops", "[rng]") {
using Catch::SimplePcg32;
REQUIRE(SimplePcg32{} == SimplePcg32{}); // C2039: "value": is not an element of "Catch::Detail::is_eq_comparable<LhsT,Catch::SimplePcg32,void>" SelfTest ...\14.16.27023\include\type_traits 74 When I reduce the header include to the following in #include <catch2/catch_test_macros.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/internal/catch_floating_point_helpers.hpp>
// #include <catch2/internal/catch_random_integer_helpers.hpp>
#include <catch2/internal/catch_random_number_generator.hpp>
// #include <catch2/internal/catch_random_seed_generation.hpp>
// #include <catch2/internal/catch_uniform_floating_point_distribution.hpp>
// #include <catch2/internal/catch_uniform_integer_distribution.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/matchers/catch_matchers_range_equals.hpp>
TEST_CASE("Comparison ops", "[rng]") {
using Catch::SimplePcg32;
REQUIRE(SimplePcg32{} == SimplePcg32{});
REQUIRE(SimplePcg32{ 0 } != SimplePcg32{});
REQUIRE_FALSE(SimplePcg32{ 1 } == SimplePcg32{ 2 });
REQUIRE_FALSE(SimplePcg32{ 1 } != SimplePcg32{ 1 });
} Catch version: v3.5.2 |
Verified with the SelfTest of Catch v3.5.2 - Checked with the other compiler Visual Studio locally: The results for Visual Studio 2019 & Visual Studio 2022 where expected, since they are part of the Windows builds Question is, why is Visual Studio 2017 v141 not part of this test-builds. Is Visual Studio 2017not official supported any more? Catch version: v3.5.2 |
2017 is currently not supported. The support policy is C++14 + maybe reasonable workarounds. Since I haven't used 2017 since, ..., well, ever, I am not interested in figuring out a workaround for VS2017 to accept the new RNG code. If you are interested in figuring it out, I can point you to |
Hi horenmar, |
In the meantime I was able to narrow down the problem further. The compiler stumbles with the == operator of a template structure. #include <catch2/catch_test_macros.hpp>
namespace Catch {
namespace Detail {
template <typename T>
struct MyTemplate {
friend bool operator==( MyTemplate const& lhs,MyTemplate const& rhs ) { return false; }
};
} // namespace Detail
} // namespace Catch
namespace Catch {
struct MyClass {
friend bool operator==( MyClass const& lhs, MyClass const& rhs ) { return false; }
};
} // namespace Catch
TEST_CASE( "first", "[x]" ) {
Catch::Detail::MyTemplate<std::uint64_t> aa; // comment this line to get rid of the error
CHECK_FALSE( std::string( "Hallo" ) == std::string( "huhu" ) );
Catch::MyClass a, b;
CHECK_FALSE( a == b ); // will generate compile error, when aa is defined
} Then comes CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == ) A simple but unpleasant solution is to put the template struct/class in its own namespace, such as Catch::Detail::Internal. Puting all the code of the How about making the new RNG code deactivable using the CMAKE option? That would also mean Catch2 is usable with Visual Studio 2017. |
Actually it looks like making the operator not-friend is sufficient: https://godbolt.org/z/783xW6jT5 |
(I would be willing to merge that PR) |
…end operator == (catchorg#2792). Make the operator not-friend is a sufficient solution.
…end operator == (catchorg#2792). Make the operator not-friend is a sufficient solution. Closes catchorg#2792
Description
There is a compiler error, when
#include <catch2/catch_all.hpp>
is included.Error msg is:
C2039: "value": is not an element of "Catch::Detail::is_eq_comparable<LhsT,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,void>"
Simple example when the error occurs:
Using the include
catch2/catch_test_macros.hpp
instead ofcatch2/catch_all.hpp
all is fineReproduction steps
Including
catch2/catch_all.hpp
in one of the catch internal tests (e.g. String.tests.cpp) reproduce this error too.Platform information:
Using v3.4.0 all is fine.
The text was updated successfully, but these errors were encountered: