Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8341931

os_linux gtest uses lambdas with explicit capture lists

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • hotspot
    • b20

      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.

            kbarrett Kim Barrett
            kbarrett Kim Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: