diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -16721,10 +16721,22 @@ AssertExpr = FullAssertExpr.get(); llvm::APSInt Cond; + Expr *BaseExpr = AssertExpr; + AllowFoldKind FoldKind = NoFold; + + if (!getLangOpts().CPlusPlus) { + // In C mode only allow folding and strip the implicit conversion + // to the type of the first _Static_assert argument that would + // otherwise suppress diagnostics for arguments that convert to int. + FoldKind = AllowFold; + while (auto *BaseCast = dyn_cast(BaseExpr)) + BaseExpr = BaseCast->getSubExpr(); + } + if (!Failed && VerifyIntegerConstantExpression( - AssertExpr, &Cond, - diag::err_static_assert_expression_is_not_constant) - .isInvalid()) + BaseExpr, &Cond, + diag::err_static_assert_expression_is_not_constant, + FoldKind).isInvalid()) Failed = true; if (!Failed && !Cond) { diff --git a/clang/test/Sema/static-assert.c b/clang/test/Sema/static-assert.c --- a/clang/test/Sema/static-assert.c +++ b/clang/test/Sema/static-assert.c @@ -5,7 +5,7 @@ _Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}} #ifndef __cplusplus -// expected-error@-2 {{static assertion expression is not an integral constant expression}} +// ext-warning@-2 {{expression is not an integer constant}} #endif _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}