Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-50264

Better FeatureCompatibility const correctness

    • Fully Compatible
    • Repl 2020-09-07

      I was surprised when

      if (const auto& fcv = serverGlobalParams.featureCompatibility; fcv.isVersionInitialized() &&
          fcv.isGreaterThanOrEqualTo(ServerGlobalParams::FeatureCompatibility::Version::kVersion47)) {
          // ...

      wouldn't compile. So the newly-added accessors (isLessThanOrEqualTo, isGreaterThanOrEqualTo, isLessThan, isGreaterThan, isUpgradingOrDowngrading) should be const-qualified.

      However in addition to this it might be better if serverGlobalParams.featureCompatibility was a const ref, with some other name for the places that legitimately need to modify it, eg.

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       struct ServerGlobalParams {
           // ...
           struct FeatureCompatibility {
               // ...
      -    } featureCompatibility;
      +    } featureCompatibilityMutable;
      +    const FeatureCompatibility& featureCompatibility = featureCompatibilityMutable;
           // ...

      This would have caught the missing const-qualifier on the accessors when they were added (in addition to helping prevent accidents).

            lingzhi.deng@mongodb.com Lingzhi Deng
            kevin.pulo@mongodb.com Kevin Pulo
            0 Vote for this issue
            3 Start watching this issue