@@ -12671,7 +12671,7 @@ void Sema::CheckMSVCRTEntryPoint(FunctionDecl *FD) {
12671
12671
}
12672
12672
}
12673
12673
12674
- bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT ) {
12674
+ bool Sema::CheckForConstantInitializer(Expr *Init, unsigned DiagID ) {
12675
12675
// FIXME: Need strict checking. In C89, we need to check for
12676
12676
// any assignment, increment, decrement, function-calls, or
12677
12677
// commas outside of a sizeof. In C99, it's the same list,
@@ -12689,8 +12689,7 @@ bool Sema::CheckForConstantInitializer(Expr *Init, QualType DclT) {
12689
12689
const Expr *Culprit;
12690
12690
if (Init->isConstantInitializer(Context, false, &Culprit))
12691
12691
return false;
12692
- Diag(Culprit->getExprLoc(), diag::err_init_element_not_constant)
12693
- << Culprit->getSourceRange();
12692
+ Diag(Culprit->getExprLoc(), DiagID) << Culprit->getSourceRange();
12694
12693
return true;
12695
12694
}
12696
12695
@@ -13808,29 +13807,24 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
13808
13807
// OpenCL v1.2 s6.5.3: __constant locals must be constant-initialized.
13809
13808
// This is true even in C++ for OpenCL.
13810
13809
} else if (VDecl->getType().getAddressSpace() == LangAS::opencl_constant) {
13811
- CheckForConstantInitializer(Init, DclT );
13810
+ CheckForConstantInitializer(Init);
13812
13811
13813
- // Otherwise, C++ does not restrict the initializer.
13812
+ // Otherwise, C++ does not restrict the initializer.
13814
13813
} else if (getLangOpts().CPlusPlus) {
13815
13814
// do nothing
13816
13815
13817
13816
// C99 6.7.8p4: All the expressions in an initializer for an object that has
13818
13817
// static storage duration shall be constant expressions or string literals.
13819
13818
} else if (VDecl->getStorageClass() == SC_Static) {
13820
- CheckForConstantInitializer(Init, DclT );
13819
+ CheckForConstantInitializer(Init);
13821
13820
13822
- // C89 is stricter than C99 for aggregate initializers.
13823
- // C89 6.5.7p3: All the expressions [...] in an initializer list
13824
- // for an object that has aggregate or union type shall be
13825
- // constant expressions.
13821
+ // C89 is stricter than C99 for aggregate initializers.
13822
+ // C89 6.5.7p3: All the expressions [...] in an initializer list
13823
+ // for an object that has aggregate or union type shall be
13824
+ // constant expressions.
13826
13825
} else if (!getLangOpts().C99 && VDecl->getType()->isAggregateType() &&
13827
13826
isa<InitListExpr>(Init)) {
13828
- const Expr *Culprit;
13829
- if (!Init->isConstantInitializer(Context, false, &Culprit)) {
13830
- Diag(Culprit->getExprLoc(),
13831
- diag::ext_aggregate_init_not_constant)
13832
- << Culprit->getSourceRange();
13833
- }
13827
+ CheckForConstantInitializer(Init, diag::ext_aggregate_init_not_constant);
13834
13828
}
13835
13829
13836
13830
if (auto *E = dyn_cast<ExprWithCleanups>(Init))
@@ -13963,7 +13957,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
13963
13957
// Avoid duplicate diagnostics for constexpr variables.
13964
13958
if (!getLangOpts().CPlusPlus && !VDecl->isInvalidDecl() &&
13965
13959
!VDecl->isConstexpr())
13966
- CheckForConstantInitializer(Init, DclT );
13960
+ CheckForConstantInitializer(Init);
13967
13961
}
13968
13962
13969
13963
QualType InitType = Init->getType();
0 commit comments