[PATCH] Update the coding standards to provide some guidance for a few constructs in C++11

Sean Silva silvas at purdue.edu
Sat Mar 1 15:42:34 PST 2014



================
Comment at: docs/CodingStandards.rst:490-502
@@ +489,15 @@
+
+  dyn_switch(V->stripPointerCasts(),
+             [] (PHINode *PN) {
+               // process phis...
+             },
+             [] (SelectInst *SI) {
+               // process selects...
+             },
+             [] (LoadInst *LI) {
+               // process loads...
+             },
+             [] (AllocaInst *AI) {
+               // process allocas...
+             });
+
----------------
Sort of random, but it seems like clang-format doesn't get this quite right. Maybe we should add something to the coding standard describing how to work around/with clang-format to get desirable results?

E.g.

First attempt, no coercion:

    int foo() {
      dyn_switch(V->stripPointerCasts(), [](PHINode *PN) {
                                           // process phis...
                                         },
                 [](SelectInst *SI) {
                   // process selects...
                 },
                 [](LoadInst *LI) {
                   // process loads...
                 },
                 [](AllocaInst *AI) {
        // process allocas...
      });
    }

Adding one comment:

    int foo() {
      dyn_switch(V->stripPointerCasts(), //
                 [](PHINode *PN) {
                   // process phis...
                 },
                 [](SelectInst *SI) {
                   // process selects...
                 },
                 [](LoadInst *LI) {
                   // process loads...
                 },
                 [](AllocaInst *AI) {
        // process allocas...
      });
    }


And then, for the "hanging" last lambda:

    int foo() {
      dyn_switch(V->stripPointerCasts(), //
                 [](PHINode *PN) {
                   // process phis...
                 },
                 [](SelectInst *SI) {
                   // process selects...
                 },
                 [](LoadInst *LI) {
                   // process loads...
                 },
                 [](AllocaInst *AI) {
                   // process allocas...
                 }//
                 );
    }

(The lack of space before that line comment is PR19017).


http://llvm-reviews.chandlerc.com/D2905



More information about the llvm-commits mailing list