diff options
author | Mark Zeren <mzeren@vmware.com> | 2018-02-05 15:59:00 +0000 |
---|---|---|
committer | Mark Zeren <mzeren@vmware.com> | 2018-02-05 15:59:00 +0000 |
commit | 1c3afaf50a0b6b96ab53740006b0bd99fd0eb1d5 (patch) | |
tree | f902281dcd64e2a891338e859b1838332c71bcb3 /clang/unittests/Format/FormatTest.cpp | |
parent | 45aa89eb7fb2d445ca55593f9a4b85933e52bc9c (diff) | |
download | bcm5719-llvm-1c3afaf50a0b6b96ab53740006b0bd99fd0eb1d5.tar.gz bcm5719-llvm-1c3afaf50a0b6b96ab53740006b0bd99fd0eb1d5.zip |
[clang-format] Re-land: Fixup #include guard indents after parseFile()
Summary:
When a preprocessor indent closes after the last line of normal code we do not
correctly fixup include guard indents. For example:
#ifndef HEADER_H
#define HEADER_H
#if 1
int i;
# define A 0
#endif
#endif
incorrectly reformats to:
#ifndef HEADER_H
#define HEADER_H
#if 1
int i;
# define A 0
# endif
#endif
To resolve this issue we must fixup levels after parseFile(). Delaying
the fixup introduces a new state, so consolidate include guard search
state into an enum.
Reviewers: krasimir, klimek
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D42035
llvm-svn: 324246
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index cbabc459c4d..e5e8fde64c9 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2547,6 +2547,20 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) { "#elif FOO\n" "#endif", Style); + // Non-identifier #define after potential include guard. + verifyFormat("#ifndef FOO\n" + "# define 1\n" + "#endif\n", + Style); + // #if closes past last non-preprocessor line. + verifyFormat("#ifndef FOO\n" + "#define FOO\n" + "#if 1\n" + "int i;\n" + "# define A 0\n" + "#endif\n" + "#endif\n", + Style); // FIXME: This doesn't handle the case where there's code between the // #ifndef and #define but all other conditions hold. This is because when // the #define line is parsed, UnwrappedLineParser::Lines doesn't hold the |