<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - spurious Wunused-lambda-capture warning?"
   href="https://llvm.org/bugs/show_bug.cgi?id=31815">31815</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>spurious Wunused-lambda-capture warning?
          </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>normal
          </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>rhalbersma@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#include <iostream>

auto sq(int c, int x) { return c * x * x; }

struct S {
    template<class Fun>
    void for_each(Fun fun) const {
        for (auto i = 1; i < 4; ++i) {
            fun(i);    
        }
    }    
};

int main()
{
    S s;
    auto sum = 0;
    s.for_each([&, i = 2](auto c) mutable {
        sum += sq(c, i++);    
    });
    std::cout << sum;   // 70 = 1 * 4 + 2 * 9 + 3 * 16
}

Works with clang up to 4.0 and gcc up to 7.0 SVN. Gives -Wunused-lambda-capture
for Clang 5.0 SVN tip-of-trunk 

See also <a href="http://stackoverflow.com/q/41960347/819272">http://stackoverflow.com/q/41960347/819272</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>