@@ -323,36 +323,52 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
323
323
bool CheckConstant (InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
324
324
assert (Desc);
325
325
326
- auto IsConstType = [&S](const VarDecl *VD) -> bool {
327
- QualType T = VD->getType ();
328
-
329
- if (T.isConstant (S.getASTContext ()))
330
- return true ;
331
-
332
- if (S.getLangOpts ().CPlusPlus && !S.getLangOpts ().CPlusPlus11 )
333
- return (T->isSignedIntegerOrEnumerationType () ||
334
- T->isUnsignedIntegerOrEnumerationType ()) &&
335
- T.isConstQualified ();
326
+ const auto *D = Desc->asVarDecl ();
327
+ if (!D || !D->hasGlobalStorage ())
328
+ return true ;
336
329
337
- if (T. isConstQualified () )
338
- return true ;
330
+ if (D == S. EvaluatingDecl )
331
+ return true ;
339
332
340
- if (const auto *RT = T-> getAs <ReferenceType> ())
341
- return RT-> getPointeeType (). isConstQualified () ;
333
+ if (D-> isConstexpr ())
334
+ return true ;
342
335
343
- if (const auto *PT = T->getAs <PointerType>())
344
- return PT->getPointeeType ().isConstQualified ();
336
+ QualType T = D->getType ();
337
+ bool IsConstant = T.isConstant (S.getASTContext ());
338
+ if (T->isIntegralOrEnumerationType ()) {
339
+ if (!IsConstant) {
340
+ diagnoseNonConstVariable (S, OpPC, D);
341
+ return false ;
342
+ }
343
+ return true ;
344
+ }
345
345
346
- return false ;
347
- };
346
+ if (IsConstant) {
347
+ if (S.getLangOpts ().CPlusPlus ) {
348
+ S.CCEDiag (S.Current ->getLocation (OpPC),
349
+ S.getLangOpts ().CPlusPlus11
350
+ ? diag::note_constexpr_ltor_non_constexpr
351
+ : diag::note_constexpr_ltor_non_integral,
352
+ 1 )
353
+ << D << T;
354
+ S.Note (D->getLocation (), diag::note_declared_at);
355
+ } else {
356
+ S.CCEDiag (S.Current ->getLocation (OpPC));
357
+ }
358
+ return true ;
359
+ }
348
360
349
- if (const auto *D = Desc->asVarDecl ();
350
- D && D->hasGlobalStorage () && D != S.EvaluatingDecl && !IsConstType (D)) {
351
- diagnoseNonConstVariable (S, OpPC, D);
352
- return false ;
361
+ if (T->isPointerOrReferenceType ()) {
362
+ if (!T->getPointeeType ().isConstant (S.getASTContext ()) ||
363
+ !S.getLangOpts ().CPlusPlus11 ) {
364
+ diagnoseNonConstVariable (S, OpPC, D);
365
+ return false ;
366
+ }
367
+ return true ;
353
368
}
354
369
355
- return true ;
370
+ diagnoseNonConstVariable (S, OpPC, D);
371
+ return false ;
356
372
}
357
373
358
374
static bool CheckConstant (InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
0 commit comments