[llvm-bugs] [Bug 52044] New: non-type template argument constexpr when passed by reference

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Oct 2 15:05:04 PDT 2021


            Bug ID: 52044
           Summary: non-type template argument constexpr when passed by
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: alexeytech at gmail.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


the following code does not work with clang++ 12 and trunk version



template<size_t N> struct S {
    static constexpr size_t n = N;

template<size_t N>
void foo(const S<N> &s) {
    std::array<char, s.n> arr;

int main() {


It fails with error

error: non-type template argument is not a constant expression
    std::array<char, s.n> arr;

The gcc and msvc compile this snippet without issues

Interestingly, if I remove the reference in foo argument type - it works.

Surprisingly the clang 12 from the LLVM windows bundle also works.


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/20211002/d9eb0932/attachment.html>

More information about the llvm-bugs mailing list