<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 - implicit [&] parameter pack capture in lambda gives error"
   href="https://bugs.llvm.org/show_bug.cgi?id=42104">42104</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>implicit [&] parameter pack capture in lambda gives error
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++14
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>niklas@nolte.dev
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When a lambda is created within another lambda, both with variadic arguments,
and the arguments of the enclosing lambda should be captured by an [&] in the
inner, certain parameter pack expansions result in the following error:

error: reference to local variable 'one' declared in enclosing lambda
expression

The problematic expansions seem to be those when there is an element wise
operation with another parameter pack.

Note that the simple expansion of `one...` does compile, and so does (if we go
to C++17) `return (((one * ...) * two) + ...);`

Also note that, when capturing [&one...] explicitly, everything compiles.


See the example code here:
#include <tuple>
int main () {
  auto first = [&] (auto... one) {
    auto faulty = [&] (auto... two) {
      //doesn't compile
      return std::tuple<decltype(one)...>{(one * two)...};
      //does compile
      //return std::tuple<decltype(one)...>{one...};
    };
    auto working = [&one...] (auto ... three) {
    //when explicitly capturing one..., it works
      return std::tuple<decltype(one)...>{(one * three)...};
    };

    working(one...);
    faulty(one...);
  };
  first(5,1);
}


See the example on 
<a href="https://godbolt.org/z/nSt0cz">https://godbolt.org/z/nSt0cz</a></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>