r186889 - Don't emit open-paren fixit without close-paren.
Eli Friedman
eli.friedman at gmail.com
Mon Jul 22 16:09:39 PDT 2013
Author: efriedma
Date: Mon Jul 22 18:09:39 2013
New Revision: 186889
URL: http://llvm.org/viewvc/llvm-project?rev=186889&view=rev
Log:
Don't emit open-paren fixit without close-paren.
getLocForEndOfToken() isn't guaranteed to succeed; if it doesn't, make sure
we do something sane.
Fixes PR16673. I'm not sure how to write a testcase for this short of grepping
through the diagnostic output.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=186889&r1=186888&r2=186889&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jul 22 18:09:39 2013
@@ -7392,6 +7392,8 @@ static void diagnoseLogicalNotOnLHSofCom
SourceLocation FirstOpen = SubExpr->getLocStart();
SourceLocation FirstClose = RHS.get()->getLocEnd();
FirstClose = S.getPreprocessor().getLocForEndOfToken(FirstClose);
+ if (FirstClose.isInvalid())
+ FirstOpen = SourceLocation();
S.Diag(UO->getOperatorLoc(), diag::note_logical_not_fix)
<< FixItHint::CreateInsertion(FirstOpen, "(")
<< FixItHint::CreateInsertion(FirstClose, ")");
@@ -7400,6 +7402,8 @@ static void diagnoseLogicalNotOnLHSofCom
SourceLocation SecondOpen = LHS.get()->getLocStart();
SourceLocation SecondClose = LHS.get()->getLocEnd();
SecondClose = S.getPreprocessor().getLocForEndOfToken(SecondClose);
+ if (SecondClose.isInvalid())
+ SecondOpen = SourceLocation();
S.Diag(UO->getOperatorLoc(), diag::note_logical_not_silence_with_parens)
<< FixItHint::CreateInsertion(SecondOpen, "(")
<< FixItHint::CreateInsertion(SecondClose, ")");
More information about the cfe-commits
mailing list