This revision was automatically updated to reflect the committed changes. Closed by commit rGe7cb3283c803: [clang-format] [PR52527] can join * with /* to form an outside of comment error… (authored by MyDeveloperDay).
Changed prior to commit: https://reviews.llvm.org/D114142?vs=388696&id=389133#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D114142/new/ https://reviews.llvm.org/D114142 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 @@ -9439,6 +9439,13 @@ verifyFormat("void f() { &(*I).first; }"); verifyIndependentOfContext("f(b * /* confusing comment */ ++c);"); + verifyFormat("f(* /* confusing comment */ foo);"); + verifyFormat("void (* /*deleter*/)(const Slice &key, void *value)"); + verifyFormat("void foo(int * // this is the first paramters\n" + " ,\n" + " int second);"); + verifyFormat("double term = a * // first\n" + " b;"); verifyFormat( "int *MyValues = {\n" " *A, // Operator detection might be confused by the '{'\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3246,6 +3246,12 @@ }; if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo()) return true; // Never ever merge two identifiers. + + // Leave a space between * and /* to avoid C4138 `comment end` found outside + // of comment. + if (Left.is(tok::star) && Right.is(tok::comment)) + return true; + if (Style.isCpp()) { if (Left.is(tok::kw_operator)) return Right.is(tok::coloncolon);
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -9439,6 +9439,13 @@ verifyFormat("void f() { &(*I).first; }"); verifyIndependentOfContext("f(b * /* confusing comment */ ++c);"); + verifyFormat("f(* /* confusing comment */ foo);"); + verifyFormat("void (* /*deleter*/)(const Slice &key, void *value)"); + verifyFormat("void foo(int * // this is the first paramters\n" + " ,\n" + " int second);"); + verifyFormat("double term = a * // first\n" + " b;"); verifyFormat( "int *MyValues = {\n" " *A, // Operator detection might be confused by the '{'\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3246,6 +3246,12 @@ }; if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo()) return true; // Never ever merge two identifiers. + + // Leave a space between * and /* to avoid C4138 `comment end` found outside + // of comment. + if (Left.is(tok::star) && Right.is(tok::comment)) + return true; + if (Style.isCpp()) { if (Left.is(tok::kw_operator)) return Right.is(tok::coloncolon);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits