boost serialization crash with clang 5.0.0

Hi Malcolm,

At least, that’s how I interpret [dcl.ref] “References” (11.3.2 in latest draft), paragraph 5:

[ Note: In particular, a null reference cannot exist in a well-defined program, because the only way to create such a reference would be to bind it to the “object” obtained by indirection through a null pointer, which causes undefined behavior. … ]

Here, the null reference created from *t may technically exist in register_type, even if it’s not used, so I’d argue that clang’s 5 conclusion about UB is correct. Even more, that’s already the “indirection through a null pointer” that causes UB.

On the other hand, decltype is a pure-type manipulation, therefore there is no possible UB.

A small fix does the job: https://godbolt.org/g/mSLgqr.
Using decltype(*t) instead of passing *t as argument does not provoke the same behaviour.

The relevant snippet with changes:

template<class T, class U = typename remove_reference::type>
static void register_type(Archive &ar){
non_abstract::template register_type(ar);
}

template
static void invoke(Archive &ar, const TPtr t){
register_type<decltype(*t)>(ar);
if(NULL == t) {
ar.save_null_pointer();
return;
}
save(ar, * t);
}

Best regards,
Marek Kurdej