<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang-format: Treat macro as a if/else if/else conditional"
   href="https://bugs.llvm.org/show_bug.cgi?id=49354">49354</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-format: Treat macro as a if/else if/else conditional
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Formatter
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vlovich@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>.clang-format is configured such that `} else {` is the format of conditional
statements. The toy repro of the issue is this:

% cat test.cpp
#define IF(cond) if (cond)

IF (true) {
  doSomething();
} else {
}

Today:
% clang-format --style=file test.cpp
IF (true) { doSomething(); }
else {
}

It would be nice to be able to specify a list of macros to treat as if/else
if/else conditional statements (similarly to other macro control options like
ForEachMacros) so that the brace alignment happens correctly.

The toy example isn't contrived, just reduced. The KJ library (part of
cap'n'proto) has a KJ_IF_MAYBE that unwraps the kj::Maybe<T> object (equivalent
to std::optional) and returns the internal pointer. So typically there will be
code like:

KJ_IF_MAYBE(value, maybeSomeValue) {
  doSomethingWith(*value);
} else {
}

The .clang-format in use for these examples is:

    ---
    Language: Cpp
    Standard: c++17
    ColumnLimit: 100
    SortIncludes: false
    AllowShortIfStatementsOnASingleLine: true
    ConstructorInitializerAllOnOneLineOrOnePerLine: true
    IndentWidth: 2
    IndentCaseBlocks: true
    IndentCaseLabels: true
    PointerAlignment: Left
    DerivePointerAlignment: true
    BreakBeforeBraces: Custom
    BraceWrapping:
      AfterCaseLabel:  false
      AfterClass:      false
      AfterControlStatement: Never
      AfterEnum:       false
      AfterFunction:   false
      AfterNamespace:  false
      AfterObjCDeclaration: false
      AfterStruct:     false
      AfterUnion:      false
      AfterExternBlock: false
      BeforeCatch:     false
      BeforeElse:      false
      BeforeLambdaBody: false
      BeforeWhile:     false
      IndentBraces:    false
      SplitEmptyFunction: false
      SplitEmptyRecord: false
      SplitEmptyNamespace: false
    Cpp11BracedListStyle: true</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>