Boost logo

Boost :

Subject: Improving diagnostics on implicit instantiation of undefined template
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2019-02-21 21:01:02


Hi,

We've got number of not defined base template classes,
with often repeated forward-declarations scattered around,
later specialised for number of types.

Namely, all those dynamic_*_step_type, and others.

I'm looking into helping compiler to improve diagnostics it throws at me;
to shorten error dump and make it clearer at first sight.

One obvious tool for such purpose is `static_assert`.
Simplifying the whole situation quite a lot, here it is

// somewhere in detail/utility.hpp
namespace detail {
template <typename T>
struct undefined_specialization : std::false_type {};
} // namespace detail

// in dynamic_step.hpp
 template <typename IteratorOrLocatorOrView>
struct dynamic_x_step_type
{
    static_assert(
        detail::undefined_specialization<IteratorOrLocatorOrView>::value,
        "dynamic_x_step_type is not specialised for given type");
};

Here is a simplified example that compares the current undefined base template
with this technique: https://godbolt.org/z/x3_rxq

To me, the static_assert seems to be an improvement and, at least,
compiler includes GIL's message about the issue and
not some a generic:

error: implicit instantiation of undefined template

which needs further investigation to understand if it is a GIL bug,
or user bug or something else.

Is the static_assert any good or is undefined base template superior?
Is there any better, slicker, more modern, more idiomatic alternative?

I'm looking for comments!

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net

Boost list run by Boost-Gil-Owners