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-Aldorasi-Imprivata opened this issue Mar 4, 2019 · 3 comments
Closed
Assignees
Milestone

Comments

@Marc-Aldorasi-Imprivata
Copy link

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
Copy link
Member

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
Copy link
Member

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-Aldorasi-Imprivata
Copy link
Author

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
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
…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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants