From 5a376e2cb9be9cdb0146b7d5e4598554455bfb53 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 3 Oct 2019 01:20:27 +0000 Subject: [PATCH] PR43519: don't inject a diagnostic when constant-evaulation of a pointer-to-member call can't determine a callee. We will have produced a diagnostic already if the callee is known to be unevaluatable, and diagnosing here rejects valid code during potential constant expression checking. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373553 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ExprConstant.cpp | 7 +++++-- test/SemaCXX/constant-expression-cxx11.cpp | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 33b0380fd6..908e801234 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -6845,8 +6845,11 @@ public: HasQualifier = ME->hasQualifier(); } else if (const BinaryOperator *BE = dyn_cast(Callee)) { // Indirect bound member calls ('.*' or '->*'). - Member = dyn_cast_or_null( - HandleMemberPointerAccess(Info, BE, ThisVal, false)); + const ValueDecl *D = + HandleMemberPointerAccess(Info, BE, ThisVal, false); + if (!D) + return false; + Member = dyn_cast(D); if (!Member) return Error(Callee); This = &ThisVal; diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index bd7094f4d4..27ad0f654f 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -1108,6 +1108,11 @@ namespace MemberPointer { static_assert((int Derived::*)(int Mid<0>::*)&Mid<0>::n != (int Derived::*)(int Mid<1>::*)&Mid<1>::n, ""); static_assert(&Mid<0>::n == (int Mid<0>::*)&Base::n, ""); + + constexpr int apply(const A &a, int (A::*f)() const) { + return (a.*f)(); + } + static_assert(apply(A(2), &A::f) == 5, ""); } namespace ArrayBaseDerived { -- 2.40.0