forked from OSchip/llvm-project
[clang-tidy] Don't generate fixes for invalid new expr location in modernize-make-unique.
Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D42363 llvm-svn: 323191
This commit is contained in:
parent
8ea1a0c690
commit
c159aa6aeb
|
@ -241,6 +241,10 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
|
|||
SourceLocation NewStart = New->getSourceRange().getBegin();
|
||||
SourceLocation NewEnd = New->getSourceRange().getEnd();
|
||||
|
||||
// Skip when the source location of the new expression is invalid.
|
||||
if (NewStart.isInvalid() || NewEnd.isInvalid())
|
||||
return false;
|
||||
|
||||
std::string ArraySizeExpr;
|
||||
if (const auto* ArraySize = New->getArraySize()) {
|
||||
ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
|
||||
|
|
|
@ -498,3 +498,12 @@ void invoke_template() {
|
|||
Foo* foo;
|
||||
template_fun(foo);
|
||||
}
|
||||
|
||||
void no_fix_for_invalid_new_loc() {
|
||||
// FIXME: Although the code is valid, the end location of `new struct Base` is
|
||||
// invalid. Correct it once https://bugs.llvm.org/show_bug.cgi?id=35952 is
|
||||
// fixed.
|
||||
auto T = std::unique_ptr<Base>(new struct Base);
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use std::make_unique instead
|
||||
// CHECK-FIXES: auto T = std::unique_ptr<Base>(new struct Base);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue