[llvm-bugs] [Bug 50676] New: -Wmisleading-indentation false positive in MSVC mode (not noticing ifdefs)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 11 01:45:03 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50676

            Bug ID: 50676
           Summary: -Wmisleading-indentation false positive in MSVC mode
                    (not noticing ifdefs)
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: martin at martin.st
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, hans at chromium.org,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk,
                    rnk at google.com

$ 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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210611/9c4c2320/attachment-0001.html>


More information about the llvm-bugs mailing list