diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-06-28 12:51:24 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-06-28 12:51:24 +0000 |
commit | 1e80887d6314e3d34b0f1c4aa6ffef9999fba8ec (patch) | |
tree | 95b6fc8726f3ece5862b9f9c5f91b347657b451e /clang/tools/clang-format/ClangFormat.cpp | |
parent | 002d764f215717f75e40f7e23139a6048bd5c1a3 (diff) | |
download | bcm5719-llvm-1e80887d6314e3d34b0f1c4aa6ffef9999fba8ec.tar.gz bcm5719-llvm-1e80887d6314e3d34b0f1c4aa6ffef9999fba8ec.zip |
Use lexing mode based on FormatStyle.Standard.
Summary:
Some valid pre-C++11 constructs change meaning when lexed in C++11
mode, e.g.
#define x(_a) printf("foo"_a);
(example from http://llvm.org/bugs/show_bug.cgi?id=16342). "foo"_a is treated as
a user-defined string literal when parsed in C++11 mode.
In order to deal with this correctly, we need to set lexing mode according to
which standard the code conforms to. We already have a configuration value for
this (FormatStyle.Standard), which seems to be appropriate to use in this case
as well.
Reviewers: klimek
CC: cfe-commits, gribozavr
Differential Revision: http://llvm-reviews.chandlerc.com/D1028
llvm-svn: 185149
Diffstat (limited to 'clang/tools/clang-format/ClangFormat.cpp')
-rw-r--r-- | clang/tools/clang-format/ClangFormat.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 764200308d0..33b7be9f1ea 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -163,7 +163,6 @@ static bool format(std::string FileName) { return true; } FileID ID = createInMemoryFile(FileName, Code.get(), Sources, Files); - Lexer Lex(ID, Sources.getBuffer(ID), Sources, getFormattingLangOpts()); if (Offsets.empty()) Offsets.push_back(0); if (Offsets.size() != Lengths.size() && @@ -195,8 +194,10 @@ static bool format(std::string FileName) { } Ranges.push_back(CharSourceRange::getCharRange(Start, End)); } - tooling::Replacements Replaces = - reformat(getStyle(Style, FileName), Lex, Sources, Ranges); + FormatStyle FormatStyle = getStyle(Style, FileName); + Lexer Lex(ID, Sources.getBuffer(ID), Sources, + getFormattingLangOpts(FormatStyle.Standard)); + tooling::Replacements Replaces = reformat(FormatStyle, Lex, Sources, Ranges); if (OutputXML) { llvm::outs() << "<?xml version='1.0'?>\n<replacements xml:space='preserve'>\n"; |