<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 - -Wmisleading-indentation false positive in MSVC mode (not noticing ifdefs)"
   href="https://bugs.llvm.org/show_bug.cgi?id=50676">50676</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wmisleading-indentation false positive in MSVC mode (not noticing ifdefs)
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>martin@martin.st
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, hans@chromium.org, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, rnk@google.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat msvc-misleading-indent.cpp 
int c;

template <class T> class MyClass {
public:
    void myMethod(int a, int B);
};

template <class T>
void MyClass<T>::myMethod(int a, int b) {
    if (a)
        return;
#ifdef TRY
    try {
#endif
        c = a + b;
#ifdef TRY
    } catch (...) { 
    }
#endif
}

void myfunc(void) {
    MyClass<int> obj;
    obj.myMethod(1, 2);
}
$ clang++ -target x86_64-windows-gnu -Wall -c msvc-misleading-indent.cpp 
$ clang++ -target x86_64-windows-msvc -Wall -c msvc-misleading-indent.cpp 
msvc-misleading-indent.cpp:15:9: warning: misleading indentation; statement is
not part of the previous 'if' [-Wmisleading-indentation]
        c = a + b; 
        ^
msvc-misleading-indent.cpp:10:5: note: previous statement is here 
    if (a)
    ^ 
1 warning generated.



Here, for targets other than MSVC, the warning about misleading indentation is
silenced thanks to the ifdef between the if statement and later line that can
be seen as possibly incorrectly indented. However when parsing this code in
MSVC mode, the warning about misleading indentation triggers.

It seems to require some amount of templating involved to trigger - for simpler
testcases, the warning is silenced due to the ifdef in MSVC mode too.

This triggers in practice in libc++'s sstream header if building with
_LIBCPP_NO_EXCEPTIONS.</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>