From 0d76241f77b89d81da4c1536bd4dc3e954a67668 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Wed, 23 Aug 2017 16:08:44 -0600 Subject: [PATCH] Avoid capture of constexpr value --- include/chaiscript/dispatchkit/bootstrap.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 201c3af7..030da21e 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -23,10 +23,10 @@ namespace chaiscript void array(const std::string &type, Module& m) { typedef typename std::remove_extent::type ReturnType; - const auto extent = std::extent::value; m.add(user_type(), type); m.add(fun( - [extent](T& t, size_t index)->ReturnType &{ + [](T& t, size_t index)->ReturnType &{ + constexpr const auto extent = std::extent::value; if (extent > 0 && index >= extent) { throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent)); } else { @@ -37,7 +37,8 @@ namespace chaiscript ); m.add(fun( - [extent](const T &t, size_t index)->const ReturnType &{ + [](const T &t, size_t index)->const ReturnType &{ + constexpr const auto extent = std::extent::value; if (extent > 0 && index >= extent) { throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent)); } else { @@ -48,8 +49,8 @@ namespace chaiscript ); m.add(fun( - [extent](const T &) { - return extent; + [](const T &) { + return std::extent::value; }), "size"); }