diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-15 13:38:33 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-15 13:38:33 +0000 |
commit | e01bab587cd283e2c1813e9a74bf50827309feaf (patch) | |
tree | 09ed6ded56bb45a11758ff4923308808383f59d3 /clang/unittests/Format/FormatTest.cpp | |
parent | 9ab63f68fcff6027cf35ec01a952be3ac000fcb9 (diff) | |
download | bcm5719-llvm-e01bab587cd283e2c1813e9a74bf50827309feaf.tar.gz bcm5719-llvm-e01bab587cd283e2c1813e9a74bf50827309feaf.zip |
Fixes various bugs around the keywords class, struct and union.
This switches to parsing record definitions only if we can clearly
identify them. We're specifically allowing common patterns for
visibility control through macros and attributes, but we cannot
currently fix all instances. This fixes all known bugs we have though.
Before:
static class A f() {
return g();
} int x;
After:
static class A f() {
return g();
}
int x;
llvm-svn: 172530
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f8a81b59820..e9fa666f907 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -1290,8 +1290,37 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) { "}"); } -TEST_F(FormatTest, BracedInitListWithElaboratedTypeSpecifier) { +TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { + // Elaborate type variable declarations. verifyFormat("struct foo a = { bar };\nint n;"); + verifyFormat("class foo a = { bar };\nint n;"); + verifyFormat("union foo a = { bar };\nint n;"); + + // Elaborate types inside function definitions. + verifyFormat("struct foo f() {}\nint n;"); + verifyFormat("class foo f() {}\nint n;"); + verifyFormat("union foo f() {}\nint n;"); + + // Templates. + verifyFormat("template <class X> void f() {}\nint n;"); + verifyFormat("template <struct X> void f() {}\nint n;"); + verifyFormat("template <union X> void f() {}\nint n;"); + + // Actual definitions... + verifyFormat("struct {} n;"); + verifyFormat("template <template <class T, class Y>, class Z > class X {} n;"); + verifyFormat("union Z {\n int n;\n} x;"); + verifyFormat("class MACRO Z {} n;"); + verifyFormat("class MACRO(X) Z {} n;"); + verifyFormat("class __attribute__(X) Z {} n;"); + verifyFormat("class __declspec(X) Z {} n;"); + + // Elaborate types where incorrectly parsing the structural element would + // break the indent. + verifyFormat("if (true)\n" + " class X x;\n" + "else\n" + " f();\n"); } // FIXME: This breaks the order of the unwrapped lines: |