================ @@ -260,6 +260,12 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT, diag::ext_initializer_string_for_char_array_too_long) << Str->getSourceRange(); else if (StrLength - 1 == ArrayLen) { + // If the string literal is null-terminated explicitly, e.g., `char a[4] = + // "ABC\0"`, there should be no warning: + if (const auto *SL = dyn_cast<StringLiteral>(Str->IgnoreParens()); + SL && SL->getLength() > 0 && + SL->getCodeUnit(SL->getLength() - 1) == 0) + return; ---------------- efriedma-quic wrote:
I think the early return suppresses warn_initializer_string_for_char_array_too_long_for_cpp warnings? https://github.com/llvm/llvm-project/pull/143487 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits