[llvm-bugs] [Bug 43519] New: Failing compilation of dereferencing pointer-to-member function in constexpr function context

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 1 01:21:42 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43519

            Bug ID: 43519
           Summary: Failing compilation of dereferencing pointer-to-member
                    function in constexpr function context
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: pierre.landrock at web.de
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The following code was compiling fine in previous Clang versions (checked from
4.0.0 up to 8.0.0). It also compiles using GCC. However, using Clang 9.0.0, it
fails to compile with the message that a subexpression is not valid in a
constant expression.

--------

struct S
{
    constexpr int doubleValue(const int input) const
    {
        return 2 * input;
    }

    constexpr double doubleValue(const double input) const
    {
        return 2 * input;
    }
};

template <typename TReturn>
struct Overloader
{
    template <typename TClass, typename ...TArgs>
    constexpr auto operator()(TReturn (TClass::* const method)(TArgs...) const)
const
    {
         return method;
    }
};

constexpr int criticalFunction()
{
    S s;
    Overloader<int> overloader;

    auto method = overloader(&S::doubleValue);
    int value{(s.*method)(21)};

    return value;
}

int main()
{
    constexpr int result{criticalFunction()};
    static_assert(result == 42, "fail");
    return result;
}

-------

The error occurs inside 'criticalFuntion' in the line where 'method' is
dereferenced.

Moving the code from 'criticalFunction' to 'main', and adding a constexpr
specifier to both 'method' and 'value' will make the code compile. Hence, the
issue seems to be bound to constexpr function context.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191001/a2f8aaab/attachment.html>


More information about the llvm-bugs mailing list