euhlmann created this revision. euhlmann added a project: clang. Change 272124* introduced a regression in spaceRequiredBetween for left aligned pointers to decltype and typeof expressions. This fix adds logic to fix this. The test added is based on a related test in determineStarAmpUsage. Also add test cases for the regression.
- http://llvm.org/viewvc/llvm-project?view=revision&revision=272124 LLVM bug tracker: https://bugs.llvm.org/show_bug.cgi?id=30407 https://reviews.llvm.org/D35847 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTest.cpp Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -5351,6 +5351,9 @@ verifyFormat("for (;; *a = b) {\n}", Left); verifyFormat("return *this += 1;", Left); verifyFormat("throw *x;", Left); + verifyFormat("delete *x;", Left); + verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left); + verifyFormat("[](const decltype(*a)* ptr) {}", Left); verifyIndependentOfContext("a = *(x + y);"); verifyIndependentOfContext("a = &(x + y);"); @@ -5397,9 +5400,6 @@ verifyGoogleFormat("T** t = new T*;"); verifyGoogleFormat("T** t = new T*();"); - FormatStyle PointerLeft = getLLVMStyle(); - PointerLeft.PointerAlignment = FormatStyle::PAS_Left; - verifyFormat("delete *x;", PointerLeft); verifyFormat("STATIC_ASSERT((a & b) == 0);"); verifyFormat("STATIC_ASSERT(0 == (a & b));"); verifyFormat("template <bool a, bool b> " Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2202,7 +2202,10 @@ if (Left.is(tok::l_square) && Right.is(tok::amp)) return false; if (Right.is(TT_PointerOrReference)) - return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) || + return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl && + !(Left.MatchingParen && Left.MatchingParen->Previous && + Left.MatchingParen->Previous->isOneOf(tok::kw_typeof, + tok::kw_decltype))) || (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous && Left.Previous->is(tok::r_paren)) || (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -5351,6 +5351,9 @@ verifyFormat("for (;; *a = b) {\n}", Left); verifyFormat("return *this += 1;", Left); verifyFormat("throw *x;", Left); + verifyFormat("delete *x;", Left); + verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left); + verifyFormat("[](const decltype(*a)* ptr) {}", Left); verifyIndependentOfContext("a = *(x + y);"); verifyIndependentOfContext("a = &(x + y);"); @@ -5397,9 +5400,6 @@ verifyGoogleFormat("T** t = new T*;"); verifyGoogleFormat("T** t = new T*();"); - FormatStyle PointerLeft = getLLVMStyle(); - PointerLeft.PointerAlignment = FormatStyle::PAS_Left; - verifyFormat("delete *x;", PointerLeft); verifyFormat("STATIC_ASSERT((a & b) == 0);"); verifyFormat("STATIC_ASSERT(0 == (a & b));"); verifyFormat("template <bool a, bool b> " Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2202,7 +2202,10 @@ if (Left.is(tok::l_square) && Right.is(tok::amp)) return false; if (Right.is(TT_PointerOrReference)) - return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) || + return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl && + !(Left.MatchingParen && Left.MatchingParen->Previous && + Left.MatchingParen->Previous->isOneOf(tok::kw_typeof, + tok::kw_decltype))) || (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous && Left.Previous->is(tok::r_paren)) || (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits