diff options
| author | Johel Ernesto Guerrero Peña <johelegp@gmail.com> | 2019-01-14 22:37:37 -0400 |
|---|---|---|
| committer | Anna Gringauze <annagrin@microsoft.com> | 2019-01-14 18:37:37 -0800 |
| commit | 6eeed739f1acb81c8b69ceae11bd5f350dab3601 (patch) | |
| tree | cac48905f3f43323c85fa7277b52b32c7c797d1d | |
| parent | 9ff6e19ea9e2ecf48488c0865be85bb1ca183279 (diff) | |
| download | platform_external_Microsoft-GSL-6eeed739f1acb81c8b69ceae11bd5f350dab3601.tar.gz platform_external_Microsoft-GSL-6eeed739f1acb81c8b69ceae11bd5f350dab3601.tar.bz2 platform_external_Microsoft-GSL-6eeed739f1acb81c8b69ceae11bd5f350dab3601.zip | |
Make narrow constexpr (#698)
| -rw-r--r-- | include/gsl/gsl_util | 9 | ||||
| -rw-r--r-- | tests/utils_tests.cpp | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/include/gsl/gsl_util b/include/gsl/gsl_util index 542bbaa..1558044 100644 --- a/include/gsl/gsl_util +++ b/include/gsl/gsl_util @@ -37,6 +37,12 @@ #endif // _MSC_VER < 1910 #endif // _MSC_VER +#if (defined(_MSC_VER) && _MSC_VER < 1910) || (!defined(__clang__) && defined(__GNUC__) && __GUNC__ < 6) +#define GSL_CONSTEXPR_NARROW 0 +#else +#define GSL_CONSTEXPR_NARROW 1 +#endif + namespace gsl { // @@ -111,6 +117,9 @@ namespace details template <class T, class U> GSL_SUPPRESS(type.1) // NO-FORMAT: attribute GSL_SUPPRESS(f.6) // NO-FORMAT: attribute // TODO: MSVC /analyze does not recognise noexcept(false) +#if GSL_CONSTEXPR_NARROW +constexpr +#endif T narrow(U u) noexcept(false) { T t = narrow_cast<T>(u); diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp index 05f8d0f..5cacd97 100644 --- a/tests/utils_tests.cpp +++ b/tests/utils_tests.cpp @@ -126,4 +126,8 @@ TEST_CASE("narrow") n = -42; CHECK_THROWS_AS(narrow<unsigned>(n), narrowing_error); + +#if GSL_CONSTEXPR_NARROW + static_assert(narrow<char>(120) == 120, "Fix GSL_CONSTEXPR_NARROW"); +#endif } |
