[llvm-bugs] [Bug 40242] New: SFINAE does not work properly with type aliases

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 7 00:31:05 PST 2019


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

            Bug ID: 40242
           Summary: SFINAE does not work properly with type aliases
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mingxwa at microsoft.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Created attachment 21299
  --> https://bugs.llvm.org/attachment.cgi?id=21299&action=edit
The code that triggers the bug

This bug was found when I was writing traits for some types with `std::void_t`.
Although `std::void_t` is a component in C++17, I have tested some previous
versions of LLVM in C++11 mode with similar code, and the bug also exists.

To trigger the bug, we could simply define a class template which taskes a
default parameter of type `std::void_t<Expressions...>`, for example:

template <class T, class = std::void_t<decltype(std::declval<T>().func())>>
struct my_traits {};

In the code above, `my_traits<T>` shall be an ill-formed expression if
`std::declval<T>().func()` is not well-formed. However, LLVM will treat
`my_traits<T>` as a well-formed expression regardless whether
`std::declval<T>().func()` is well-formed.

To verify this conclusion, we could write another type traits for `my_triats`:

template <class T, class SFINAE = void>
struct has_my_traits : std::false_type {};

template <class T>
struct has_my_traits<T, std::void_t<my_traits<T>>> : std::true_type {};

The following assertion will fire in LLVM, but works fine with GCC or MSVC:

static_assert(!has_my_traits<int>::value, "Oops!");

-- 
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/20190107/bc80e68b/attachment-0001.html>


More information about the llvm-bugs mailing list