[llvm-bugs] [Bug 28711] New: error: non-type template argument is not a constant expression (GCC compiles, clang doesn't)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 26 01:25:14 PDT 2016


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

            Bug ID: 28711
           Summary: error: non-type template argument is not a constant
                    expression (GCC compiles, clang doesn't)
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: weiss at wsoptics.de
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

I believe that the following code is valid C++14 and should compile.  GCC 5.4.0
does compile it without warnings:

-----------------------
#include <array>
#include <cstddef>
#include <utility>

namespace detail {
    namespace detail {
        template<typename R, typename F, typename A, std::size_t... index>
            constexpr decltype(auto) func_apply_impl(F && f, A && a,
std::index_sequence<index...>)
            {
                return R{f(std::forward<A>(a)[index])...};
            }
    }
    //! Take an object a of type A that has size() and operator[] and return
R{f(a[0]), ..., f(a[a.size()-1])}
    template<typename R, typename F, typename A>
        constexpr decltype(auto) func_apply(F && f, A && a)
        {
            return detail::func_apply_impl<R>(std::forward<F>(f),
std::forward<A>(a), std::make_index_sequence<a.size()>{});
        }

}

template<typename T, std::size_t N> constexpr auto operator*(T const t,
std::array<T, N> const & rhs) { return detail::func_apply<std::array<T, N>>([t]
(const auto r) { return t * r; }, rhs); }

int main()
{
    const std::array<int, 3> a{1, 2, 3};

    const auto b = 2 * a;

    return 0;
}
----------------------

It might be related to 28385, but it behaves the same with both --std=c++14 and
--std=c++1z


clang 3.8.1 gives:
/tmp/z.cpp:17:103: error: non-type template argument is not a constant
expression
        return detail::func_apply_impl<R>(std::forward<F>(f),
std::forward<A>(a), std::make_index_sequence<a.size()>{});

-- 
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/20160726/0c5c3029/attachment.html>


More information about the llvm-bugs mailing list