@@ -579,61 +579,57 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
579
579
return false ;
580
580
}
581
581
582
- if (F->isConstexpr () && F->hasBody () && F->getDecl ()->isConstexpr ())
583
- return true ;
584
-
585
- // Implicitly constexpr.
586
- if (F->isLambdaStaticInvoker ())
587
- return true ;
588
-
589
- const SourceLocation &Loc = S.Current ->getLocation (OpPC);
590
- if (S.getLangOpts ().CPlusPlus11 ) {
591
- const FunctionDecl *DiagDecl = F->getDecl ();
582
+ if (!F->isConstexpr () || !F->hasBody ()) {
583
+ const SourceLocation &Loc = S.Current ->getLocation (OpPC);
584
+ if (S.getLangOpts ().CPlusPlus11 ) {
585
+ const FunctionDecl *DiagDecl = F->getDecl ();
592
586
593
- // Invalid decls have been diagnosed before.
594
- if (DiagDecl->isInvalidDecl ())
595
- return false ;
587
+ // Invalid decls have been diagnosed before.
588
+ if (DiagDecl->isInvalidDecl ())
589
+ return false ;
596
590
597
- // If this function is not constexpr because it is an inherited
598
- // non-constexpr constructor, diagnose that directly.
599
- const auto *CD = dyn_cast<CXXConstructorDecl>(DiagDecl);
600
- if (CD && CD->isInheritingConstructor ()) {
601
- const auto *Inherited = CD->getInheritedConstructor ().getConstructor ();
602
- if (!Inherited->isConstexpr ())
603
- DiagDecl = CD = Inherited;
604
- }
591
+ // If this function is not constexpr because it is an inherited
592
+ // non-constexpr constructor, diagnose that directly.
593
+ const auto *CD = dyn_cast<CXXConstructorDecl>(DiagDecl);
594
+ if (CD && CD->isInheritingConstructor ()) {
595
+ const auto *Inherited = CD->getInheritedConstructor ().getConstructor ();
596
+ if (!Inherited->isConstexpr ())
597
+ DiagDecl = CD = Inherited;
598
+ }
605
599
606
- // FIXME: If DiagDecl is an implicitly-declared special member function
607
- // or an inheriting constructor, we should be much more explicit about why
608
- // it's not constexpr.
609
- if (CD && CD->isInheritingConstructor ()) {
610
- S.FFDiag (Loc, diag::note_constexpr_invalid_inhctor, 1 )
600
+ // FIXME: If DiagDecl is an implicitly-declared special member function
601
+ // or an inheriting constructor, we should be much more explicit about why
602
+ // it's not constexpr.
603
+ if (CD && CD->isInheritingConstructor ()) {
604
+ S.FFDiag (Loc, diag::note_constexpr_invalid_inhctor, 1 )
611
605
<< CD->getInheritedConstructor ().getConstructor ()->getParent ();
612
- S.Note (DiagDecl->getLocation (), diag::note_declared_at);
613
- } else {
614
- // Don't emit anything if the function isn't defined and we're checking
615
- // for a constant expression. It might be defined at the point we're
616
- // actually calling it.
617
- bool IsExtern = DiagDecl->getStorageClass () == SC_Extern;
618
- if (!DiagDecl->isDefined () && !IsExtern && DiagDecl-> isConstexpr () &&
619
- S.checkingPotentialConstantExpression ())
620
- return false ;
606
+ S.Note (DiagDecl->getLocation (), diag::note_declared_at);
607
+ } else {
608
+ // Don't emit anything if the function isn't defined and we're checking
609
+ // for a constant expression. It might be defined at the point we're
610
+ // actually calling it.
611
+ bool IsExtern = DiagDecl->getStorageClass () == SC_Extern;
612
+ if (!DiagDecl->isDefined () && !IsExtern &&
613
+ S.checkingPotentialConstantExpression ())
614
+ return false ;
621
615
622
- // If the declaration is defined, declared 'constexpr' _and_ has a body,
623
- // the below diagnostic doesn't add anything useful.
624
- if (DiagDecl->isDefined () && DiagDecl->isConstexpr () &&
625
- DiagDecl->hasBody ())
626
- return false ;
616
+ // If the declaration is defined, declared 'constexpr' _and_ has a body,
617
+ // the below diagnostic doesn't add anything useful.
618
+ if (DiagDecl->isDefined () && DiagDecl->isConstexpr () &&
619
+ DiagDecl->hasBody ())
620
+ return false ;
627
621
628
- S.FFDiag (Loc, diag::note_constexpr_invalid_function, 1 )
622
+ S.FFDiag (Loc, diag::note_constexpr_invalid_function, 1 )
629
623
<< DiagDecl->isConstexpr () << (bool )CD << DiagDecl;
630
- S.Note (DiagDecl->getLocation (), diag::note_declared_at);
624
+ S.Note (DiagDecl->getLocation (), diag::note_declared_at);
625
+ }
626
+ } else {
627
+ S.FFDiag (Loc, diag::note_invalid_subexpr_in_const_expr);
631
628
}
632
- } else {
633
- S.FFDiag (Loc, diag::note_invalid_subexpr_in_const_expr);
629
+ return false ;
634
630
}
635
631
636
- return false ;
632
+ return true ;
637
633
}
638
634
639
635
bool CheckCallDepth (InterpState &S, CodePtr OpPC) {
0 commit comments