[llvm-bugs] [Bug 24770] New: wrong template partial specialization instantiated in constexpr context

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 10 07:12:16 PDT 2015


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

            Bug ID: 24770
           Summary: wrong template partial specialization instantiated in
                    constexpr context
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zilla at kayari.org
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

This originated at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67537 where
Ville's additional SFINAE constraints for N4387 (improving pair and tuple v3)
cause clang to barf on libstdc++'s tuple.

This is a reduced version, which G++ accepts but Clang rejects:


template<typename T, typename U>
struct pair { };

template<typename... _Elements>
constexpr bool sink(_Elements&&...);

template<bool, typename... _Elements>
struct _TC
{
  template<typename... _UElements>
  static constexpr bool _MoveConstructibleTuple()
  {
    return sink( pair<_Elements, _UElements>{} ... );
  }
};

template<typename... _Elements>
struct _TC<false, _Elements...>
{
  template<typename... _UElements>
  static constexpr bool _MoveConstructibleTuple()
  {
    return false;
  }
};

template<bool>
struct enable_if { using type = bool; };

template<>
struct enable_if<false> { };

template<typename... _Elements>
struct tuple
{
  template<typename... _UElements> using _TMC =
        _TC<(sizeof...(_Elements) == sizeof...(_UElements)), _Elements...>;

  template<typename... _UElements, typename
           enable_if<_TMC<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()>::type=true>
      constexpr tuple(_UElements&&...) { }

  constexpr tuple() { }
};

struct X { };

constexpr tuple<X> t{};


Clang says:

c.cc:13:48: error: pack expansion contains parameter packs '_Elements' and
'_UElements' that have different lengths (1 vs. 0)
    return sink( pair<_Elements, _UElements>{} ... );
                      ~~~~~~~~~  ~~~~~~~~~~    ^
c.cc:40:52: note: in instantiation of function template specialization
'_TC<true, X>::_MoveConstructibleTuple<>' requested here
           enable_if<_TMC<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()>::type=true>
                                                   ^
c.cc:41:17: note: while substituting prior template arguments into non-type
template parameter [with _UElements = <>]
      constexpr tuple(_UElements&&...) { }
                ^~~~~
c.cc:34:8: note: while substituting deduced template arguments into function
template 'tuple' [with _UElements = <>, $1 = (no value)]
struct tuple
       ^
1 error generated.


The error comes from a member of _TC<true, X> but the _TMC alias template
should ensure that _TC<false, X> is used when the packs have different sizes.

-- 
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/20150910/e8637c50/attachment.html>


More information about the llvm-bugs mailing list