Skip to content

Existence of default destructor causes impenetrable error message #327

Open
@rebcabin

Description

Please consider the following Minimal Example:

template<typename Num>
class MinHeapX {
    std::unique_ptr<Num[]> array_;
    int capacity_{}; // maximum possible size of min heap

public:
    MinHeapX() = delete;

    explicit MinHeapX(int capacity) : capacity_(capacity),
                                      array_(std::make_unique<Num[]>(capacity)) {
        if (capacity <= 0) {
            throw std::invalid_argument("Capacity must be at least 1.");
        }
    }

    // ~MinHeapX() = default; // ************* ATTENTION! TROUBLE ***********

    [[nodiscard]] int getCapacity() const {
        return capacity_;
    }
};

namespace rc {

    template<>
    struct Arbitrary<MinHeapX<int>> {
    static Gen<MinHeapX<int>>

    arbitrary() {
        return gen::map(gen::inRange<int>(1, 10),
                        [](int capacity) {
                            return MinHeapX<int>(capacity);
                        });
    }
};

and the following use in Google test (not using rapidcheck's GoogleTest integration)

TEST(HeapsInt, RapidCheck) {
    rc::check("Check MinHeapX capacity",
              [](const MinHeapX<int> &heap) {
                  RC_ASSERT(heap.getCapacity() >= 1);
                  RC_ASSERT(heap.getCapacity() <= 10);
              });
}

This works as expected. However, uncommenting the line ~MinHeapX() = default; generates the following error message from rapidcheck. This error message is not particularly prescriptive, I had to bisect my code to isolate the problem. I'd like to point out that explicitly declaring a default destructor is often considered good practice, but it rendered my class untestable. I'll also point out that it seems it's the unique_pointer<Num[]> array_ is entailed in the problem, though I did not produce another careful bisection to determine exactly how.


In template: no matching conversion for functional-style cast from 'MinHeapX<int>' to 
'tuple<typename __unwrap_ref_decay<MinHeapX<int>>::type>' (aka 'tuple<MinHeapX<int>>') 
error occurred here in instantiation of function template specialization 
'std::make_tuple<MinHeapX<int>>' requested here in instantiation of member function 
'rc::gen::detail::TupleShrinkable<rc::detail::IntSequence<unsigned long, 0>, 
MinHeapX<int>>::value' requested here in instantiation of member function 
'rc::Shrinkable<std::tuple<MinHeapX<int>>>::ShrinkableImpl<rc::gen::detail::TupleShrinka
ble<rc::detail::IntSequence<unsigned long, 0>, MinHeapX<int>>>::value' requested here in 
instantiation of function template specialization 
'rc::Shrinkable<std::tuple<MinHeapX<int>>>::ShrinkableImpl<rc::gen::detail::TupleShrinka
ble<rc::detail::IntSequence<unsigned long, 0>, 
MinHeapX<int>>>::ShrinkableImpl<rc::Shrinkable<M... in instantiation of function 
template specialization 
'rc::makeShrinkable<rc::gen::detail::TupleShrinkable<rc::detail::IntSequence<unsigned 
long, 0>, MinHeapX<int>>, rc::Shrinkable<MinHeapX<int>>>' requested here (skipping 10 
contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all) in instantiation of 
function template specialization 
'rc::gen::detail::shrinkableWithRecipe<rc::detail::PropertyAdapter<(lambda at /Users/
brian/Dropbox/Mac/Documents/GitHub/CLionProjects/Heaps/test/HeapsGTest.cpp:72:15)>>' 
requested here in instantiation of function template specialization 
'rc::gen::detail::execRaw<rc::detail::PropertyAdapter<(lambda at /Users/brian/Dropbox/
Mac/Documents/GitHub/CLionProjects/Heaps/test/HeapsGTest.cpp:72:15)>>' requested here in 
instantiation of function template specialization 'rc::detail::toProperty<(lambda at /
Users/brian/Dropbox/Mac/Documents/GitHub/CLionProjects/Heaps/test/
HeapsGTest.cpp:72:15)>' requested here in instantiation of function template 
specialization 'rc::detail::checkTestable<(lambda at /Users/brian/Dropbox/Mac/Documents/
GitHub/CLionProjects/Heaps/test/HeapsGTest.cpp:72:15), rc::detail::TestMetadata &>' 
requested here in instantiation of function template specialization 'rc::check<(lambda 
at /Users/brian/Dropbox/Mac/Documents/GitHub/CLionProjects/Heaps/test/
HeapsGTest.cpp:72:15)>' requested here candidate template ignored: requirement 
'integral_constant<bool, false>::value' was not satisfied [with _And = std::_And] 
candidate template ignored: requirement 'integral_constant<bool, false>::value' was not 
satisfied [with _And = std::_And] candidate template ignored: requirement 
'integral_constant<bool, false>::value' was not satisfied [with _Up = <MinHeapX<int>>] 
candidate template ignored: requirement 'integral_constant<bool, false>::value' was not 
satisfied [with _Up = <MinHeapX<int>>] candidate template ignored: could not match 
'tuple' against 'MinHeapX' candidate template ignored: could not match 'tuple' against 
'MinHeapX' candidate template ignored: could not match 'tuple' against 'MinHeapX' 
candidate template ignored: could not match 'tuple' against 'MinHeapX' candidate 
template ignored: could not match 'pair' against 'MinHeapX' candidate template ignored: 
could not match 'pair' against 'MinHeapX' candidate template ignored: could not match 
'pair' against 'MinHeapX' candidate template ignored: could not match 'pair' against 
'MinHeapX' candidate constructor template not viable: requires 0 arguments, but 1 was 
provided candidate constructor template not viable: requires 0 arguments, but 1 was 
provided candidate constructor template not viable: requires 2 arguments, but 1 was 
provided candidate constructor template not viable: requires 2 arguments, but 1 was 
provided candidate constructor template not viable: requires 3 arguments, but 1 was 
provided candidate constructor template not viable: requires 3 arguments, but 1 was 
provided candidate constructor template not viable: requires at least 2 arguments, but 1 was provided

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions