================ @@ -260,6 +260,11 @@ 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 warn: + if (const auto *SL = dyn_cast<StringLiteral>(Str->IgnoreParens())) + if (SL->isOrdinary() && SL->getBytes().back() == 0) ---------------- AaronBallman wrote:
Also, this means the functionality only works for `char` and not other string types. I would imagine we'd want to also support: `wchar_t foo[4] = { L'f', L'o', L'o', L'\0' };` and other variants. 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