[SERVER-40160] clang-format mishandles constexpr-if Created: 15/Mar/19  Updated: 29/Oct/23  Resolved: 29/Jul/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.3.1

Type: Bug Priority: Major - P3
Reporter: Sara Golemon Assignee: ADAM Martin (Inactive)
Resolution: Fixed Votes: 0
Labels: clang-format
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
is caused by SERVER-41772 Deploy Clang Format 7.0.1 to the code... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.2
Sprint: Dev Tools 2019-07-29
Participants:

 Description   

clang-format produces formatting which would seem to indicate it doesn't actually understand constexpr-if expressions as seen in the following output from clang-format as run on evergreen during the `lint` task.

      * Returns the bounds on the smallest and largest possible plaintext for the ciphertext.
      */
     std::pair<size_t, size_t> expectedPlaintextLen() const {
-        if constexpr (Header::kMode == aesMode::cbc) {
-            return {getDataSize() - crypto::aesBlockSize, getDataSize()};
-        } else {
+        if
+            constexpr(Header::kMode == aesMode::cbc) {
+                return {getDataSize() - crypto::aesBlockSize, getDataSize()};
+            }
+        else {
             invariant(Header::kMode == aesMode::gcm);
             return {getDataSize(), getDataSize()};
         }



 Comments   
Comment by Githook User [ 27/Jul/19 ]

Author:

{'name': 'ADAM David Alan Martin', 'email': 'adam.martin@10gen.com', 'username': 'adamlsd'}

Message: SERVER-40160 Remove `if_constexpr.h` header.

This header circumvented bad formatting which `clang-format-3.8`
imparted to `if constexpr`. Now `clang-format-7.0.1` imparts
a reasonable format to `if constexpr` so this header is not
needed anymore.
Branch: master
https://github.com/mongodb/mongo/commit/ca57a4d640aee04ef373a50b24e79d85f0bb91a0

Comment by Githook User [ 27/Jul/19 ]

Author:

{'name': 'ADAM David Alan Martin', 'email': 'adam.martin@10gen.com', 'username': 'adamlsd'}

Message: SERVER-40160 Fix if-constexpr with new clang-format
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/813a8370fd3784a79ffc1da28b82bf22532eef92

Comment by Billy Donahue [ 16/May/19 ]

In the meantime,

#include "mongo/util/if_constexpr.h"
...
IF_CONSTEXPR(...) {
  ...
} else {
  ...
}

Generated at Thu Feb 08 04:54:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.