[llvm-bugs] [Bug 45506] New: Erroneous "if constexpr" instantiation in lambda template

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Apr 12 12:58:10 PDT 2020


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

            Bug ID: 45506
           Summary: Erroneous "if constexpr" instantiation in lambda
                    template
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: leigh at i42.co.uk
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

clang++ erroneously instantiates the "if constexpr" statement commented "pfft"
below; g++ and VS2019 accept it on local consensus is that it is a clang++ bug:

#include <cstdint>
#include <type_traits>
#include <variant>
#include <iostream>

template <typename T>
T foo(const std::variant<int64_t, double, std::string>& v)
{
    T result;
    std::visit([&result](auto&& a)
    {
        typedef std::decay_t<decltype(a)> vt;
        if constexpr (std::is_same_v<vt, double>)
            result = static_cast<T>(a);
        else if constexpr (std::is_same_v<vt, int64_t>)
            result = static_cast<T>(a);
        else if constexpr (std::is_same_v<vt, std::string> &&
std::is_class_v<T>)
            result = T::from_string(a); // pfft
        else
            throw std::logic_error("wibble");
    }, v);
    return result;
}

int main()
{
    std::cout << foo<double>(int64_t{});
}

-- 
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/20200412/7a7e9e07/attachment.html>


More information about the llvm-bugs mailing list