diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-21 13:58:54 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-21 13:58:54 +0000 |
commit | cdee74db63260b89a73fbdf0b726511e286af58f (patch) | |
tree | 42407ef018c791578e77673604f07ba162a5d84b /clang/lib/Format | |
parent | 5f37c821547d2881ddc30ee03c990d96111458f5 (diff) | |
download | bcm5719-llvm-cdee74db63260b89a73fbdf0b726511e286af58f.tar.gz bcm5719-llvm-cdee74db63260b89a73fbdf0b726511e286af58f.zip |
Fixes detection of class template specializations.
Now correctly formats:
template <> class A<int> {} a;
llvm-svn: 173038
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index dffc309a09e..7f9e97eab00 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -620,7 +620,17 @@ void UnwrappedLineParser::parseRecord() { FormatTok.Tok.is(tok::coloncolon)) nextToken(); - if (FormatTok.Tok.is(tok::colon)) { + // Note that parsing away template declarations here leads to incorrectly + // accepting function declarations as record declarations. + // In general, we cannot solve this problem. Consider: + // class A<int> B() {} + // which can be a function definition or a class definition when B() is a + // macro. If we find enough real-world cases where this is a problem, we + // can parse for the 'template' keyword in the beginning of the statement, + // and thus rule out the record production in case there is no template + // (this would still leave us with an ambiguity between template function + // and class declarations). + if (FormatTok.Tok.is(tok::colon) || FormatTok.Tok.is(tok::less)) { while (FormatTok.Tok.isNot(tok::l_brace)) { if (FormatTok.Tok.is(tok::semi)) return; @@ -630,6 +640,9 @@ void UnwrappedLineParser::parseRecord() { } if (FormatTok.Tok.is(tok::l_brace)) parseBlock(); + // We fall through to parsing a structural element afterwards, so + // class A {} n, m; + // will end up in one unwrapped line. } void UnwrappedLineParser::parseObjCProtocolList() { |