[llvm-bugs] [Bug 33655] New: Work around CWG issue 1558 (guarantee SFINAE when using `void_t`)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 30 05:45:20 PDT 2017


https://bugs.llvm.org/show_bug.cgi?id=33655

            Bug ID: 33655
           Summary: Work around CWG issue 1558 (guarantee SFINAE when
                    using `void_t`)
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vittorio.romeo at outlook.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

In both libstdc++ and libc++ `void_t` is currently implemented as:

    template <class...> using void_t = void;

Due to a CWG issue (#1558), unused parameters in alias templates are not
guaranteed to ensure SFINAE and could be ignored:
http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1558

This causes code like this to surprisingly fail to compile:

    struct One { using x = int; };
    struct Two { using y = int; };

    template <typename T, std::void_t<typename T::x>* = nullptr>
    void func() {}
    template <typename T, std::void_t<typename T::y>* = nullptr>
    void func() {}

    int main() { func<One>(); }

There's a workaround for this issue available on cppreference. I propose to use
it to implement `void_t` to guarantee SFINAE-friendliness:

    template<typename... Ts> struct make_void { typedef void type;};
    template<typename... Ts> using void_t = typename make_void<Ts...>::type;

From:
http://en.cppreference.com/w/cpp/types/void_t

Context/more information:
https://stackoverflow.com/questions/44845945

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170630/cb2512db/attachment.html>


More information about the llvm-bugs mailing list