@@ -12769,7 +12769,7 @@ void Sema::DiagnoseHLSLAttrStageMismatch(
12769
12769
<< (AllowedStages.size() != 1) << join(StageStrings, ", ");
12770
12770
}
12771
12771
12772
- bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT ) {
12772
+ bool Sema::CheckForConstantInitializer(Expr *Init, unsigned DiagID ) {
12773
12773
// FIXME: Need strict checking. In C89, we need to check for
12774
12774
// any assignment, increment, decrement, function-calls, or
12775
12775
// commas outside of a sizeof. In C99, it's the same list,
@@ -12787,8 +12787,7 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
12787
12787
const Expr *Culprit;
12788
12788
if (Init->isConstantInitializer(Context, false, &Culprit))
12789
12789
return false;
12790
- Diag(Culprit->getExprLoc(), diag::err_init_element_not_constant)
12791
- << Culprit->getSourceRange();
12790
+ Diag(Culprit->getExprLoc(), DiagID) << Culprit->getSourceRange();
12792
12791
return true;
12793
12792
}
12794
12793
@@ -13906,29 +13905,24 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
13906
13905
// OpenCL v1.2 s6.5.3: __constant locals must be constant-initialized.
13907
13906
// This is true even in C++ for OpenCL.
13908
13907
} else if (VDecl->getType().getAddressSpace() == LangAS::opencl_constant) {
13909
- CheckForConstantInitializer(Init, DclT );
13908
+ CheckForConstantInitializer(Init, diag::err_init_element_not_constant );
13910
13909
13911
- // Otherwise, C++ does not restrict the initializer.
13910
+ // Otherwise, C++ does not restrict the initializer.
13912
13911
} else if (getLangOpts().CPlusPlus) {
13913
13912
// do nothing
13914
13913
13915
13914
// C99 6.7.8p4: All the expressions in an initializer for an object that has
13916
13915
// static storage duration shall be constant expressions or string literals.
13917
13916
} else if (VDecl->getStorageClass() == SC_Static) {
13918
- CheckForConstantInitializer(Init, DclT );
13917
+ CheckForConstantInitializer(Init, diag::err_init_element_not_constant );
13919
13918
13920
- // C89 is stricter than C99 for aggregate initializers.
13921
- // C89 6.5.7p3: All the expressions [...] in an initializer list
13922
- // for an object that has aggregate or union type shall be
13923
- // constant expressions.
13919
+ // C89 is stricter than C99 for aggregate initializers.
13920
+ // C89 6.5.7p3: All the expressions [...] in an initializer list
13921
+ // for an object that has aggregate or union type shall be
13922
+ // constant expressions.
13924
13923
} else if (!getLangOpts().C99 && VDecl->getType()->isAggregateType() &&
13925
13924
isa<InitListExpr>(Init)) {
13926
- const Expr *Culprit;
13927
- if (!Init->isConstantInitializer(Context, false, &Culprit)) {
13928
- Diag(Culprit->getExprLoc(),
13929
- diag::ext_aggregate_init_not_constant)
13930
- << Culprit->getSourceRange();
13931
- }
13925
+ CheckForConstantInitializer(Init, diag::ext_aggregate_init_not_constant);
13932
13926
}
13933
13927
13934
13928
if (auto *E = dyn_cast<ExprWithCleanups>(Init))
@@ -14061,7 +14055,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
14061
14055
// Avoid duplicate diagnostics for constexpr variables.
14062
14056
if (!getLangOpts().CPlusPlus && !VDecl->isInvalidDecl() &&
14063
14057
!VDecl->isConstexpr())
14064
- CheckForConstantInitializer(Init, DclT );
14058
+ CheckForConstantInitializer(Init, diag::err_init_element_not_constant );
14065
14059
}
14066
14060
14067
14061
QualType InitType = Init->getType();
0 commit comments