[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG7ee4236789bb: [clang-format] clang-format eats space in front of attributes for operator… (authored by MyDeveloperDay). Changed prior to commit: https://reviews.llvm.org/D116920?vs=398864=399563#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void *ptr) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1893,6 +1893,13 @@ LeftOfParens = LeftOfParens->MatchingParen->Previous; } + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; + // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. if (LeftOfParens->Tok.getIdentifierInfo() && Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void *ptr) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1893,6 +1893,13 @@ LeftOfParens = LeftOfParens->MatchingParen->Previous; } + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; + // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. if (LeftOfParens->Tok.getIdentifierInfo() && ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
curdeius accepted this revision. curdeius added a comment. This revision is now accepted and ready to land. LGTM. Don't forget to reformat. It's a pity though that we cannot use `MightBeFunctionDecl`. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
MyDeveloperDay updated this revision to Diff 398864. MyDeveloperDay added a comment. remove additional space CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void *ptr) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1892,6 +1892,14 @@ return false; LeftOfParens = LeftOfParens->MatchingParen->Previous; } + + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void *ptr) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1892,6 +1892,14 @@ return false; LeftOfParens = LeftOfParens->MatchingParen->Previous; } + + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
MyDeveloperDay updated this revision to Diff 398863. MyDeveloperDay added a comment. clang-format CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void *ptr ) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1892,6 +1892,14 @@ return false; LeftOfParens = LeftOfParens->MatchingParen->Previous; } + + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void *ptr ) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1892,6 +1892,14 @@ return false; LeftOfParens = LeftOfParens->MatchingParen->Previous; } + + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
MyDeveloperDay updated this revision to Diff 398861. MyDeveloperDay added a comment. Line.MightBeFunctionDecl is not true in this case Added new tests CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void* ptr ) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1892,6 +1892,14 @@ return false; LeftOfParens = LeftOfParens->MatchingParen->Previous; } + + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,11 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); + verifyFormat("void operator delete[](void *foo) ATTRIB;"); + verifyFormat("void operator delete(void* ptr ) noexcept;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1892,6 +1892,14 @@ return false; LeftOfParens = LeftOfParens->MatchingParen->Previous; } + + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
curdeius added inline comments. Comment at: clang/unittests/Format/FormatTest.cpp:9463 + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); Please add a test for `operator delete[]`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
MyDeveloperDay added inline comments. Comment at: clang/lib/Format/TokenAnnotator.cpp:1729 } else if (Current.is(tok::r_paren)) { if (rParenEndsCast(Current)) Current.setType(TT_CastRParen); curdeius wrote: > The current solution looks a bit like a hack to me. > Unless I'm mistaken, casts can appear only in expressions, but not in > declarations (except for inside `decltype` stuff in templates or concepts, > but these are still expressions at this level). > Given that `void operator delete...` is not an expression but a declaration, > we shouldn't check `rParenEndsCast` in this case at all, no? > So, would it be possible to check here for e.g. `Line.MightBeFunctionDecl` or > something like this to avoid it? > > Also, how is it that you don't need to special-case `new` operator? I will check to see if we can use that.. To answer your second question, the existing code was this... `!isOneOf(Keywords.kw_in, tok::kw_return, tok::kw_case,tok::kw_delete)` its the `kw_delete` here that breaks the previous code. to cover this being a cast `delete (A *)a;` my change is to use more context by avoid `operator delete (A* a) a;` from being seen as a cast Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
curdeius added inline comments. Comment at: clang/lib/Format/TokenAnnotator.cpp:1729 } else if (Current.is(tok::r_paren)) { if (rParenEndsCast(Current)) Current.setType(TT_CastRParen); The current solution looks a bit like a hack to me. Unless I'm mistaken, casts can appear only in expressions, but not in declarations (except for inside `decltype` stuff in templates or concepts, but these are still expressions at this level). Given that `void operator delete...` is not an expression but a declaration, we shouldn't check `rParenEndsCast` in this case at all, no? So, would it be possible to check here for e.g. `Line.MightBeFunctionDecl` or something like this to avoid it? Also, how is it that you don't need to special-case `new` operator? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D116920/new/ https://reviews.llvm.org/D116920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D116920: [clang-format] clang-format eats space in front of attributes for operator delete
MyDeveloperDay created this revision. MyDeveloperDay added reviewers: curdeius, HazardyKnusperkeks, owenpan, thakis. MyDeveloperDay added projects: clang, clang-format. MyDeveloperDay requested review of this revision. https://github.com/llvm/llvm-project/issues/27037 Sorry its taken so long to get to this issue! (got it before it hit its 6th birthday!) void operator delete(void *foo)ATTRIB; (void *foo) is incorrectly determined to be a C-Style Cast resulting in the space being removed after the ) and before the attrib, due to the detection of delete (A* )a; The following was previously unaffected void operator new(void *foo) ATTRIB; Fixes #27037 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D116920 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,9 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1893,6 +1893,14 @@ LeftOfParens = LeftOfParens->MatchingParen->Previous; } + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->is(tok::kw_delete) && LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; + // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. if (LeftOfParens->Tok.getIdentifierInfo() && Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9459,6 +9459,9 @@ "new (aa(aaa))\n" "typename ();"); verifyFormat("delete[] h->p;"); + + verifyFormat("void operator delete(void *foo) ATTRIB;"); + verifyFormat("void operator new(void *foo) ATTRIB;"); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1893,6 +1893,14 @@ LeftOfParens = LeftOfParens->MatchingParen->Previous; } + // The Condition directly below this one will see the operator arguments + // as a (void *foo) cast. + // void operator delete(void *foo) ATTRIB; + if (LeftOfParens->Tok.getIdentifierInfo() && + LeftOfParens->is(tok::kw_delete) && LeftOfParens->Previous && + LeftOfParens->Previous->is(tok::kw_operator)) +return false; + // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. if (LeftOfParens->Tok.getIdentifierInfo() && ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits