diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/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); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/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"