For some reasons, I've always thought that deduction guides must have the same noexcept
-ness of the constructor to which they refer. For example:
template<typename T>
struct clazz {
clazz(const T &) noexcept {}
};
clazz(const char &) noexcept -> clazz<int>;
That is, if the constructor is noexcept
and I want it to be so also for const char &
, I have to add the noexcept
specifier to the deduction guide as well.
Today I worked a little with ICC and found that it has problems with noexcept
on deduction guides. So far, so good. I thought it was a bug of the compiler and that's it.
However, I went to look into the standard and couldn't find any point that confirms my initial assumption. Because of that, I checked the same against clang and even if it works without problems, it seems that the noexcept
on the deduction guide gets ignored in 100% of cases. On the other side, the one on the constructor affects both.
So, my question is, does it make any sense or is it required to somewhat propagate (if this makes sense at all) the noexcept
-ness of the constructor also to the deduction guide or is it useless and I can just get rid of all noexcept
on deduction guides?
The grammar for the deduction guide is defined in [temp.deduct.guide]/1 as
explicit-specifier(opt) template-name ( parameter-declaration-clause ) -> simple-template-id ;
and as you can see, it does not include a exception specifier.
This does make sense. The deduction guide doesn't actually construct anything. It is just used to tell the compiler how to get the template parameters from a set of arguments. You have a two step process, the deduction guide(s) run through overload resolution to determine the template parameters, and then the constructors are enumerated with those deduced template parameters, and overload resolution is run against the constructors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With