[cfe-dev] Wish: Split Wunused-lambda-capture

Tobias Hahn via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 5 08:50:24 PDT 2018

In migrating our codebase to Xcode 9.3, I came across the new warning -Wunused-lambda-capture. This seems like a helpful warning to enable; yet unfortunately I cannot due to incompatibility with MSVC.

The problem is that it warns on the following code (https://godbolt.org/g/HDiqR8):

int times2(int num) {
  const int two = 2;
  auto multiply = [two](int i) { return i * two; };
  return multiply(num);

Per the standard, it is unnecessary to capture `two` because it is an integral constant. MSVC doesn't know about this, and throws C3493 (variable cannot be implicitly captured) if I remove `two` from the capture clause to fix clang's -Wunused-lambda-capture (https://godbolt.org/g/VNNfqT).

Since I don't expect MSVC to be standards compliant any time soon, it would be great if this warning could be split into two warnings:

-Wunused-lambda-capture would only warn on truly unused captures, but not captures that are merely unnecessary (but still used as in the example above).

-Wunnecessary-lambda-capture would warn on redundant explicit captures (as in the example above).

Thanks for considering my wish and making clang even better!


Ableton AG, Schoenhauser Allee 6-7, 10119 Berlin, Germany
Sitz (Registered Office) Berlin, Amtsgericht Berlin-Charlottenburg, HRB 72838
Vorstand (Management Board): Gerhard Behles, Jan Bohl
Vorsitzender des Aufsichtsrats (Chair of the Supervisory Board): Uwe Struck

More information about the cfe-dev mailing list