Skip to content
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

BOOST_TEST_CHECK can't compare abstract classes using gcc #209

Closed
marc-groundctl opened this issue Mar 4, 2019 · 3 comments

Comments

@marc-groundctl
Copy link

commented Mar 4, 2019

struct abstract
{
    virtual ~abstract() = 0;
    bool operator==(const abstract &) const;
};

std::ostream &operator<<(std::ostream &, const abstract &);

void foo(abstract &a)
{
    BOOST_TEST_CHECK(a == a); // Fails
    BOOST_CHECK_EQUAL(a, a); // Works
}

Godbolt. When compiling this code, GCC complains that it can't instantiate the member functions of std::numeric_limits with an abstract type. Boost Test should check if numeric_limits is instantiable with a specific type before attempting to instantiate it; see https://stackoverflow.com/questions/16505782/determining-if-stdnumeric-limitst-is-safe-to-instantiate for a longer discussion of the issue and possible implementations.

@raffienficiaud

This comment has been minimized.

Copy link
Member

commented Mar 4, 2019

I've made a fix, annoyingly the problem does not happen on clang/OSX. Waiting for CI checks.

@raffienficiaud raffienficiaud self-assigned this Mar 4, 2019

@raffienficiaud

This comment has been minimized.

Copy link
Member

commented Mar 5, 2019

Would it be possible for you to check the branch topic/GH-209-BOOST_TEST-abstract-class-compare. Right now it contains some failures on C++03 for comparing abstract classes (not sure I will be able to improve the support there) but otherwise seems to do the job.

@marc-groundctl

This comment has been minimized.

Copy link
Author

commented Mar 6, 2019

That branch works for me.

@raffienficiaud raffienficiaud added 1.71 and removed 1.71 labels May 13, 2019

@raffienficiaud raffienficiaud added this to the 1.71 milestone Jul 21, 2019

raffienficiaud added a commit that referenced this issue Jul 21, 2019
Helper for retricting the use of numeric_limits to complete types
Fixes GH-209.
A new helper meta-function has been added to check if the type under
test is complete or not. Incomplete types cannot be used with
std::numeric_limits.

The newly added test cannot be run on pre C++11 because of the limited
BOOST_TEST support (unrelated to the std::numeric_limits issue).
raffienficiaud added a commit that referenced this issue Jul 21, 2019
Merge branch 'topic/GH-209-BOOST_TEST-abstract-class-compare' into ne…
…xt-internal

* topic/GH-209-BOOST_TEST-abstract-class-compare:
  Change log
  Helper for restricting the use of numeric_limits to complete types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.