[llvm-bugs] [Bug 51973] New: Default non-type template parameters with immediately invoked lambdas fail with deduction guides

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Sep 26 03:26:30 PDT 2021


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

            Bug ID: 51973
           Summary: Default non-type template parameters with immediately
                    invoked lambdas fail with deduction guides
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: friedkeenan at protonmail.com
                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

With the following code, clang claims the defaulted non-type template parameter
is not a constant expression, despite it being so (with GCC handling it fine as
well):

#include <concepts>

template<
    typename T,
    auto V = []() {
        if constexpr (std::same_as<T, int>) {
            return 1;
        } else {
            return 2;
        }
    }()
>
struct Test {
    constexpr Test(T) { }
};

template<typename T>
Test(T) -> Test<T>;

void test() {
    Test<int, 1>(1);
}

Godbolt link: https://godbolt.org/z/jT3zPx9fx

As you can see, even if you specify the template parameters when constructing,
it still complains, and if you duplicate the immediately invoked lambda in the
deduction guide and remove the explicated template arguments for the
constructor, clang actually says that it can't compile that expression yet.
However, if you specify the template arguments, it consumes everything fine.

-- 
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/20210926/c2bdc161/attachment.html>


More information about the llvm-bugs mailing list