[llvm-bugs] [Bug 47724] New: wrong calculation for fold expression in constexpr function

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Oct 4 14:26:35 PDT 2020


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

            Bug ID: 47724
           Summary: wrong calculation for fold expression in constexpr
                    function
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kirshamir at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

The following code gets the wrong result if calculated as constexpr (but the
correct result otherwise):

template<bool...Args>
constexpr int reversed_binary_value(){ // ok if removing the constexpr, wrong
otherwise
    int res{0},tmp{0};
    (tmp|=...|=((res*=2)+=Args));
    // std::cout << res << std::endl; // ok with the cout, wrong otherwise
    return res;
}

int main()
{
    auto val = reversed_binary_value<1,0,1,0>();
    assert((val==5)); // ok
    assert((reversed_binary_value<1,0,1,0>()==5)); // fails
}

code: https://godbolt.org/z/Pvq67r

-- 
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/20201004/3b2436e6/attachment.html>


More information about the llvm-bugs mailing list