aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-01-17 09:39:01 -0500
committerJack Lloyd <[email protected]>2019-01-17 09:39:01 -0500
commitdc799b9eb8cb2970541c283dc285f3cd282cb119 (patch)
tree21df33c7876afe7f7432a239748ef86e45d056c4 /src
parent377ed5445083af5703fe8b0411ad162af1766012 (diff)
Define BOTAN_IF_CONSTEXPR
This lets us avoid some warnings under VC++ 2017
Diffstat (limited to 'src')
-rw-r--r--src/lib/utils/calendar.cpp13
-rw-r--r--src/lib/utils/compiler.h12
-rw-r--r--src/lib/utils/simd/simd_32.h4
-rw-r--r--src/lib/utils/simd/simd_avx2/simd_avx2.h4
4 files changed, 25 insertions, 8 deletions
diff --git a/src/lib/utils/calendar.cpp b/src/lib/utils/calendar.cpp
index fe04f1d23..1c34a7157 100644
--- a/src/lib/utils/calendar.cpp
+++ b/src/lib/utils/calendar.cpp
@@ -65,13 +65,18 @@ std::chrono::system_clock::time_point calendar_point::to_std_timepoint() const
// 32 bit time_t ends at January 19, 2038
// https://msdn.microsoft.com/en-us/library/2093ets1.aspx
// Throw after 2037 if 32 bit time_t is used
- if(get_year() > 2037 && sizeof(std::time_t) == 4)
+
+ BOTAN_IF_CONSTEXPR(sizeof(std::time_t) == 4)
{
- throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2037 on this system");
+ if(get_year() > 2037)
+ {
+ throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2037 on this system");
+ }
}
- else if(get_year() >= 2400)
+
+ // This upper bound is completely arbitrary
+ if(get_year() >= 2400)
{
- // This upper bound is somewhat arbitrary
throw Invalid_Argument("calendar_point::to_std_timepoint() does not support years after 2400");
}
diff --git a/src/lib/utils/compiler.h b/src/lib/utils/compiler.h
index 4f736ae6c..fa8e1cfbf 100644
--- a/src/lib/utils/compiler.h
+++ b/src/lib/utils/compiler.h
@@ -131,6 +131,18 @@
#endif
/*
+* Define BOTAN_IF_CONSTEXPR
+*/
+
+#if !defined(BOTAN_IF_CONSTEXPR)
+ #if __cplusplus > 201402
+ #define BOTAN_IF_CONSTEXPR if constexpr
+ #else
+ #define BOTAN_IF_CONSTEXPR if
+ #endif
+#endif
+
+/*
* Define BOTAN_PARALLEL_FOR
*/
#if !defined(BOTAN_PARALLEL_FOR)
diff --git a/src/lib/utils/simd/simd_32.h b/src/lib/utils/simd/simd_32.h
index a2e41c20f..304770587 100644
--- a/src/lib/utils/simd/simd_32.h
+++ b/src/lib/utils/simd/simd_32.h
@@ -285,13 +285,13 @@ class SIMD_4x32 final
#else
- if(ROT == 8)
+ BOTAN_IF_CONSTEXPR(ROT == 8)
{
const uint8_t maskb[16] = { 3,0,1,2, 7,4,5,6, 11,8,9,10, 15,12,13,14 };
const uint8x16_t mask = vld1q_u8(maskb);
return SIMD_4x32(vreinterpretq_u32_u8(vqtbl1q_u8(vreinterpretq_u8_u32(m_neon), mask)));
}
- else if(ROT == 16)
+ else BOTAN_IF_CONSTEXPR(ROT == 16)
{
return SIMD_4x32(vreinterpretq_u32_u16(vrev32q_u16(vreinterpretq_u16_u32(m_neon))));
}
diff --git a/src/lib/utils/simd/simd_avx2/simd_avx2.h b/src/lib/utils/simd/simd_avx2/simd_avx2.h
index fde086e53..3f8c0b912 100644
--- a/src/lib/utils/simd/simd_avx2/simd_avx2.h
+++ b/src/lib/utils/simd/simd_avx2/simd_avx2.h
@@ -77,14 +77,14 @@ class SIMD_8x32 final
{
static_assert(ROT > 0 && ROT < 32, "Invalid rotation constant");
- if(ROT == 8)
+ BOTAN_IF_CONSTEXPR(ROT == 8)
{
const __m256i shuf_rotl_8 = _mm256_set_epi8(14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3,
14, 13, 12, 15, 10, 9, 8, 11, 6, 5, 4, 7, 2, 1, 0, 3);
return SIMD_8x32(_mm256_shuffle_epi8(m_avx2, shuf_rotl_8));
}
- else if(ROT == 16)
+ else BOTAN_IF_CONSTEXPR(ROT == 16)
{
const __m256i shuf_rotl_16 = _mm256_set_epi8(13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2,
13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2);