gtest os_linux:pretouch_thp_and_use_concurrent uses lambdas with explicit capture lists. This goes against the style guide's recommendation to use implicit reference capture (`[&]`). There is no benefit here to not using the recommended form.
The first lambda, named pretouch, was recently changed (JDK-8341722) to remove one of the variables from the capture list, apparently because clang complained about it. (The JBS issue doesn't mention this specific problem.)
In this case I think the updated explicit capture list is actively harmful, requiring a deeper knowledge of the details of lambdas, lambda capture, and expression evaluation to understand. The size variable is neither explicitly captured (by mention in the capture list), nor implicitly captured via the use of a capture-default. Instead, it's covered by other rules for an integral constant variable with a constant expression initializer, so does not need to be captured at all.
The rationale for the preference for using implicit reference capture is explicitly to reduce the cases a reader must recognize and understand. If that were used here, a reader wouldn't need to know about the constant expression rules and know it doesn't actually get captured. Instead, referential transparency applies regardless.
The first lambda, named pretouch, was recently changed (
In this case I think the updated explicit capture list is actively harmful, requiring a deeper knowledge of the details of lambdas, lambda capture, and expression evaluation to understand. The size variable is neither explicitly captured (by mention in the capture list), nor implicitly captured via the use of a capture-default. Instead, it's covered by other rules for an integral constant variable with a constant expression initializer, so does not need to be captured at all.
The rationale for the preference for using implicit reference capture is explicitly to reduce the cases a reader must recognize and understand. If that were used here, a reader wouldn't need to know about the constant expression rules and know it doesn't actually get captured. Instead, referential transparency applies regardless.
- relates to
-
JDK-8341722 Fix some warnings as errors when building on Linux with toolchain clang
- Resolved
- links to
-
Commit(master) openjdk/jdk/e4ff553c
-
Review(master) openjdk/jdk/21513