Forwarding to the bug
On 25/07/2014 08:33, Jacob Hart wrote:
> On Fri, Jul 25, 2014 at 4:00 PM, Sylvestre Ledru <[email protected]> wrote:
>> Hello,
>>
>> On 25/07/2014 06:06, hartja wrote:
>>> Package: clang-3.4
>>> Version: 1:3.4.2-4
>>> Severity: normal
>>>
>>> Dear Maintainer,
>>>
>>> I encountered a crash while building with clang++ and I am submitting this
>>> bug
>>> report as requested.
>>>
>>> Attached is an archive containing the preprocessed source file and run
>>> script
>>> that triggered the crash. Please note the code in the archive is not
>>> expected
>>> to compile cleanly; I was experimenting with the syntax at the time the
>>> crash
>>> occurred.
>>>
>> Please provide a reduced test case. I won't be able to do anything
>> otherwise.
>>
>> Thanks
>> Sylvestre
> Hi Sylvestre,
>
> Thanks for your reply. I have attached source code that triggers the
> crash to this email. Fortunately the test case is quite small -- I
> think the size blew out in the preprocessed version because of the
> includes.
>
> Regards,
> Jacob.
#include <iostream>
#include <tuple>
namespace syntax {
typedef uint32_t error_t;
}
template <typename T> struct validator;
template <typename T> struct value_type;
namespace detail {
/** @require Validatable(T)
* @require Rule(R), Rule(Rs...) defined on T */
template <typename T, typename R, typename...Rs>
struct validator_base
{
typedef T type;
typedef std::tuple<R, Rs...> rule_set_t;
rule_set_t rule_set;
syntax::error_t operator()(const T& x) const
{
return evaluate_<std::tuple_size<rule_set_t>>(x);
}
protected:
~validator_base() = default;
template <unsigned N>
syntax::error_t evaluate_(const T& x)
{
validator<T>& v = static_cast<validator<T&>>(*this);
syntax::error_t error = rule_set<N>(v, x);
return error | evaluate_<N-1>(x)<<1;
}
};
template <typename T, typename R, typename...Rs>
syntax::error_t validator_base<T, R, Rs...>::evaluate_<0>(const T& x)
{
validator<T>& v = static_cast<validator<T&>>(*this);
return rule_set<0>(v, x);
};
template <typename T, typename value_type<T>::type Min, typename value_type<T>::type Max>
struct rule_range
{
bool operator()(const validator<T>& v, const T& x) const
{
return !(Min <= x.value && x.value <= Max);
}
};
} // detail
template <> struct value_type<int>
{
typedef int type;
};
template <> struct validator<int>:
public detail::validator_base<int, detail::rule_range<int, 0, 15>>
{ };
int main(int, char **) {
validator<int> v;
std::cout << std::hex << v(1) << std::endl;
return 0;
}