@@ -165,15 +165,48 @@ void UseThisInsteadOfSingletonCheck::check(
165165 std::string Replacement = std::string (MemberName);
166166
167167 if (IsCall && MemberCall) {
168+ SourceLocation RParenLoc = MemberCall->getRParenLoc ();
168169 const Expr *Callee = MemberCall->getCallee ();
169- SourceLocation ArgsStart = Lexer::getLocForEndOfToken (
170- Callee->getEndLoc (), 0 , SM, Result.Context ->getLangOpts ());
171- SourceLocation ArgsEnd = MemberCall->getEndLoc ();
172- if (ArgsStart.isValid () && ArgsEnd.isValid () && ArgsStart < ArgsEnd) {
173- StringRef ArgsText = Lexer::getSourceText (
174- CharSourceRange::getTokenRange (ArgsStart, ArgsEnd), SM,
175- Result.Context ->getLangOpts ());
176- Replacement += ArgsText.str ();
170+
171+ if (RParenLoc.isValid () && Callee) {
172+ SourceLocation CalleeEnd = Lexer::getLocForEndOfToken (
173+ Callee->getEndLoc (), 0 , SM, Result.Context ->getLangOpts ());
174+
175+ if (CalleeEnd.isValid () && CalleeEnd < RParenLoc) {
176+ SourceLocation ArgsStart = CalleeEnd;
177+ SourceLocation ArgsEnd = Lexer::getLocForEndOfToken (
178+ RParenLoc, 0 , SM, Result.Context ->getLangOpts ());
179+
180+ if (ArgsStart.isValid () && ArgsEnd.isValid () && ArgsStart < ArgsEnd) {
181+ StringRef ArgsText = Lexer::getSourceText (
182+ CharSourceRange::getCharRange (ArgsStart, ArgsEnd), SM,
183+ Result.Context ->getLangOpts ());
184+ ArgsText = ArgsText.ltrim ();
185+ if (!ArgsText.empty ()) {
186+ Replacement += ArgsText.str ();
187+ } else {
188+ Replacement += " ()" ;
189+ }
190+ } else {
191+ Replacement += " ()" ;
192+ }
193+ } else {
194+ SourceLocation CallEnd = Lexer::getLocForEndOfToken (
195+ MemberCall->getEndLoc (), 0 , SM, Result.Context ->getLangOpts ());
196+ if (CalleeEnd.isValid () && CallEnd.isValid () && CalleeEnd < CallEnd) {
197+ StringRef ArgsText = Lexer::getSourceText (
198+ CharSourceRange::getCharRange (CalleeEnd, CallEnd), SM,
199+ Result.Context ->getLangOpts ());
200+ ArgsText = ArgsText.ltrim ();
201+ if (!ArgsText.empty ()) {
202+ Replacement += ArgsText.str ();
203+ } else {
204+ Replacement += " ()" ;
205+ }
206+ } else {
207+ Replacement += " ()" ;
208+ }
209+ }
177210 } else {
178211 Replacement += " ()" ;
179212 }
0 commit comments