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

Keane, Erich via cfe-dev cfe-dev at lists.llvm.org
Thu Apr 5 08:54:54 PDT 2018


" Since I don't expect MSVC to be standards compliant any time soon,"

I think you may wish to report this as a bug to the MSVC team.  They have been REALLY good about fixing standards compliance issues in the past two years or so.

-----Original Message-----
From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of Tobias Hahn via cfe-dev
Sent: Thursday, April 5, 2018 8:50 AM
To: cfe-dev at lists.llvm.org
Subject: [cfe-dev] Wish: Split Wunused-lambda-capture

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!

Tobias

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

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list