Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is noexcept deduction allowed in class template partial specialization?

For the program below, Clang 5 (trunk) reports that IsNoexcept is not deducible, while GCC 7.1 segfaults. What does the standard (draft) say about this? Is this a compiler QOI issue?

static_assert(__cpp_noexcept_function_type, "requires c++1z");

template<typename T>
struct is_noexcept;

template<bool IsNoexcept>
struct is_noexcept<void() noexcept(IsNoexcept)> {
    static constexpr auto value = IsNoexcept;
};

static_assert(is_noexcept<void() noexcept>::value);
static_assert(!is_noexcept<void()>::value);

int main() {}

Relates to proposal P0012.

like image 622
Barrett Adair Avatar asked May 29 '17 16:05

Barrett Adair


1 Answers

  1. [temp.deduct.type]/8 lists all forms of types from which a template argument can be deduced. The exception-specification is not in the list and hence is not deducible.
  2. As an extension, GCC permits deducing from noexcept to ease the implementation of std::is_function. It looks like the extension is only very lightly tested.
  3. The extension was first suggested by Clang's maintainer and appeared to have some support in the committee, but it's not clear if it will eventually make its way into the standard.
  4. This is not a conforming extension because it changes the meaning of well-defined code, e.g., the value of g(f) with the following snippet:

    void f() noexcept;
    
    template<bool E = false, class R>
    constexpr bool g(R (*)() noexcept(E)){
        return E;
    }
    
like image 100
T.C. Avatar answered Sep 30 '22 16:09

T.C.