This post has been republished via RSS; it originally appeared at: Microsoft Developer Blogs.
Last time, we put together a little traits class to decompose a function pointer into its components. But one thing missing from our class is the noexcept qualifier. For the remainder of the discussion, I've removed the FirstArg and LastArg type aliases, since I came to the conclusion that they aren't really needed. What's left is this: But it falls apart when we give it a noexcept function pointer. (Note that noexcept did not become part of the function pointer type until C++17.) There is no match for T because none of our specializations support noexcept function pointers. So let's add noexcept to our signatures. Let's try this version, which takes advantage of the fact that noexcept takes a Boolean parameter that says whether the noexcept applies. Saying noexcept with no parameters is shorthand for noexcept(true), and omitting noexcept is the same as noexcept(false). The Microsoft compiler doesn't like it: icc also doesn't like it, but for a different reason: It's perfectly happy to match the partial specialization to a non-noexcept function, but thinks it doesn't apply to a noexcept function. On the other hand, gcc and clang are okay with it and deduce Nonthrowing appropriately. I'm not sure who is right. (I didn't check icc.) Well that's a bummer. The parameter to noexcept is not deducible by the Microsoft compiler. We'll just have to add a separate specialization. Okay, so that takes care of the noexcept wrinkle. We'll look at another attribute next time.