LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 50676 - -Wmisleading-indentation false positive in MSVC mode (not noticing ifdefs)
Summary: -Wmisleading-indentation false positive in MSVC mode (not noticing ifdefs)
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-11 01:45 PDT by Martin Storsjö
Modified: 2021-06-14 02:03 PDT (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Storsjö 2021-06-11 01:45:03 PDT
$ 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.
Comment 1 Hans Wennborg 2021-06-14 02:03:21 PDT
-fno-delayed-template-parsing makes the warning go away in msvc mode, so I assume it's related to that.