///
/// \param Tok - Token that represents the directive
/// \param Directive - String reference for the directive name
- /// \param EndLoc - End location for fixit
- void SuggestTypoedDirective(const Token &Tok,
- StringRef Directive,
- const SourceLocation &EndLoc) const;
+ void SuggestTypoedDirective(const Token &Tok, StringRef Directive) const;
/// We just read a \#if or related directive and decided that the
/// subsequent tokens are in the \#if'd out portion of the
}
void Preprocessor::SuggestTypoedDirective(const Token &Tok,
- StringRef Directive,
- const SourceLocation &EndLoc) const {
+ StringRef Directive) const {
// If this is a `.S` file, treat unknown # directives as non-preprocessor
// directives.
if (getLangOpts().AsmPreprocessor) return;
Candidates.insert(Candidates.end(), {"elifdef", "elifndef"});
if (Optional<StringRef> Sugg = findSimilarStr(Directive, Candidates)) {
- CharSourceRange DirectiveRange =
- CharSourceRange::getCharRange(Tok.getLocation(), EndLoc);
- std::string SuggValue = Sugg.getValue().str();
-
- auto Hint = FixItHint::CreateReplacement(DirectiveRange, "#" + SuggValue);
+ // Directive cannot be coming from macro.
+ assert(Tok.getLocation().isFileID());
+ CharSourceRange DirectiveRange = CharSourceRange::getCharRange(
+ Tok.getLocation(),
+ Tok.getLocation().getLocWithOffset(Directive.size()));
+ StringRef SuggValue = Sugg.getValue();
+
+ auto Hint = FixItHint::CreateReplacement(DirectiveRange, SuggValue);
Diag(Tok, diag::warn_pp_invalid_directive) << 1 << SuggValue << Hint;
}
}
/*foundnonskip*/false,
/*foundelse*/false);
} else {
- SuggestTypoedDirective(Tok, Directive, endLoc);
+ SuggestTypoedDirective(Tok, Directive);
}
} else if (Directive[0] == 'e') {
StringRef Sub = Directive.substr(1);
}
}
} else {
- SuggestTypoedDirective(Tok, Directive, endLoc);
+ SuggestTypoedDirective(Tok, Directive);
}
} else {
- SuggestTypoedDirective(Tok, Directive, endLoc);
+ SuggestTypoedDirective(Tok, Directive);
}
CurPPLexer->ParsingPreprocessorDirective = false;
// RUN: %clang_cc1 -fsyntax-only -verify=pre-c2x-cpp2b %s
// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=c2x-cpp2b %s
// RUN: %clang_cc1 -x c++ -std=c++2b -fsyntax-only -verify=c2x-cpp2b %s
+// RUN: %clang_cc1 -x c++ -std=c++2b -fsyntax-only %s -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
// id: pre-c2x-cpp2b-warning@+12 {{invalid preprocessing directive, did you mean '#if'?}}
// ifd: pre-c2x-cpp2b-warning@+12 {{invalid preprocessing directive, did you mean '#if'?}}
#id
#ifd
#ifde
-#elf
-#elsif
+# elf
+# elsif
#elseif
#elfidef
#elfindef
// els: c2x-cpp2b-warning@-12 {{invalid preprocessing directive, did you mean '#else'?}}
// endi: c2x-cpp2b-warning@-12 {{invalid preprocessing directive, did you mean '#endif'?}}
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:4}:"if"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:5}:"if"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:6}:"ifdef"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:3-[[@LINE-24]]:6}:"elif"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:4-[[@LINE-24]]:9}:"elif"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:8}:"elif"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:9}:"elifdef"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:10}:"elifdef"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:11}:"elifndef"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:5}:"else"
+// CHECK: fix-it:{{.*}}:{[[@LINE-24]]:2-[[@LINE-24]]:6}:"endif"
+
#ifdef UNDEFINED
#i // no diagnostic
#endif