Skip to content

Commit ad7aeb0

Browse files
committed
Revert "[clang][Interp] Fix CheckCallable for undefined-and-not-constexpr fns"
This reverts commit d00b355. This breaks the ms-constexpr test: https://lab.llvm.org/buildbot/#/builders/144/builds/2605
1 parent d9cb65f commit ad7aeb0

File tree

3 files changed

+44
-63
lines changed

3 files changed

+44
-63
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -579,61 +579,57 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
579579
return false;
580580
}
581581

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();
592586

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;
596590

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+
}
605599

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)
611605
<< 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;
621615

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;
627621

628-
S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
622+
S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
629623
<< 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);
631628
}
632-
} else {
633-
S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
629+
return false;
634630
}
635631

636-
return false;
632+
return true;
637633
}
638634

639635
bool CheckCallDepth(InterpState &S, CodePtr OpPC) {

clang/lib/AST/Interp/Interp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,14 +2531,14 @@ inline bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
25312531
if (!CheckInvoke(S, OpPC, ThisPtr))
25322532
return false;
25332533
}
2534+
2535+
if (S.checkingPotentialConstantExpression())
2536+
return false;
25342537
}
25352538

25362539
if (!CheckCallable(S, OpPC, Func))
25372540
return false;
25382541

2539-
if (Func->hasThisPointer() && S.checkingPotentialConstantExpression())
2540-
return false;
2541-
25422542
if (!CheckCallDepth(S, OpPC))
25432543
return false;
25442544

clang/test/AST/Interp/cxx2a.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)