Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Wmisleading-indentation false positive in MSVC mode (not noticing ifdefs) #50020

Open
mstorsjo opened this issue Jun 11, 2021 · 1 comment
Open
Labels
bugzilla Issues migrated from bugzilla c++ clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@mstorsjo
Copy link
Member

Bugzilla Link 50676
Version trunk
OS All
CC @DougGregor,@zmodem,@zygoloid,@rnk

Extended Description

$ cat msvc-misleading-indent.cpp
int c;

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

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

void myfunc(void) {
MyClass 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.

@zmodem
Copy link
Collaborator

zmodem commented Jun 14, 2021

-fno-delayed-template-parsing makes the warning go away in msvc mode, so I assume it's related to that.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@Quuxplusone Quuxplusone added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

3 participants