<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang-cl emits bogus error: cannot decompose this type; 'std::tuple_size<const S>::value' is not a valid integral constant expression"
   href="https://bugs.llvm.org/show_bug.cgi?id=33236">33236</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-cl emits bogus error: cannot decompose this type; 'std::tuple_size<const S>::value' is not a valid integral constant expression
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sfinae@hotmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18545" name="attach_18545" title="Self-contained test case">attachment 18545</a> <a href="attachment.cgi?id=18545&action=edit" title="Self-contained test case">[details]</a></span>
Self-contained test case

Note: This is using my implementation of LWG 2770 tuple_size SFINAE, which will
ship in VS 2017's first toolset update (aka "15.3").

C:\Temp>type meow.cpp
#include <assert.h>
#include <tuple>

struct S {
    int x;
};

int main() {
    S s{99};
    auto [m1] = s;
    auto& [r1] = s;
    assert(m1 == 99);
    assert(&r1 == &s.x);

    const S cs{1729};
    auto [m2] = cs;
    auto& [r2] = cs;
    assert(m2 == 1729);
    assert(&r2 == &cs.x);
}

C:\Temp>cl
Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25326 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

usage: cl [ option... ] filename... [ /link linkoption... ]

C:\Temp>cl /EHsc /nologo /W4 /std:c++latest meow.cpp && meow
meow.cpp

C:\Temp>clang-cl -v
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: S:\WCFB01\vctools\NonShip\ClangLLVM\bin

C:\Temp>clang-cl /EHsc /nologo /W4 /std:c++latest meow.cpp && meow
meow.cpp(17,11):  error: cannot decompose this type; 'std::tuple_size<const
S>::value' is not a valid integral constant expression
    auto& [r2] = cs;
          ^
1 error generated.

I believe that this is the same issue as what I reported to the reflectors on
April 3, 2017. C1XX has implemented my preferred resolution.

--
Subject: [isocpp-lib] New issue - Core and Library disagree on tuple_size
SFINAE (LWG 2770)

LWG 2770's resolution taught tuple_size to SFINAE. However, Core's wording for
structured bindings disagrees with what the Library provides.

N4659 23.5.3.6 [tuple.helper]/4: "template <class T> class tuple_size<const T>;
template <class T> class tuple_size<volatile T>; template <class T> class
tuple_size<const volatile T>; Let TS denote tuple_size<T> of the cv-unqualified
type T. If the expression TS::value is well-formed when treated as an
unevaluated operand, then each of the three templates shall meet the
UnaryTypeTrait requirements (23.15.1) with a base characteristic of
integral_constant<size_t, TS::value> Otherwise, they shall have no member
value."

When the Library provides SFINAE, Meow<Types> is complete, it's just that
Meow<Types>::value or Meow<Types>::type is non-existent. This is the
long-standing practice followed by invoke_result, etc.

However, Core expects different behavior:

11.5 [dcl.struct.bind]/3: "Otherwise, if the qualified-id std::tuple_size<E>
names a complete type, the expression std::tuple_size<E>::value shall be a
well-formed integral constant expression and"

This wording was introduced in Issaquah as the resolution of GB 20 (thanks to
Casey for the programmer-archaeology). He found no discussion, just "ready for
vote on Friday".

I encountered this because I implemented tuple_size SFINAE with the traditional
approach (it is a complete class with no members), yet libc++ had a test
expecting tuple_size<const void> to be an incomplete class. I argue that the
Core wording should change - it should not inspect the completeness of
tuple_size<E>, but should instead inspect the well-formedness of
tuple_size<E>::value, which is what the Library is already doing when
implementing tuple_size<cv T>.

Thanks,
STL</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>