From bf51a76e4ebb728ec56f5d651a4b4e378e49afb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=20=C4=8Cerm=C3=A1k?= Date: Sat, 7 Apr 2018 00:53:09 +0200 Subject: [PATCH] [safe_op] Fix ODR violation in compiler builtin specializations The compiler instrinsics are exposed via fully specialized template functions which must not be defined twice (which they accidentally were). Declaring them as inline fixes this issue. --- src/safe_op.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/safe_op.hpp b/src/safe_op.hpp index 760b3267..fefdd6c0 100644 --- a/src/safe_op.hpp +++ b/src/safe_op.hpp @@ -1,6 +1,6 @@ // ********************************************************* -*- C++ -*- /* - * Copyright (C) 2004-2017 Exiv2 maintainers + * Copyright (C) 2004-2018 Exiv2 maintainers * * This program is part of the Exiv2 distribution. * @@ -218,13 +218,13 @@ namespace Safe * The intrinsics are documented here: * https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html#Integer-Overflow-Builtins */ -#define SPECIALIZE_builtin_add_overflow(type, builtin_name) \ - /* Full specialization of builtin_add_overflow for type using the */ \ - /* builtin_name intrinsic */ \ - template <> \ - bool builtin_add_overflow(type summand_1, type summand_2, type & result) \ - { \ - return builtin_name(summand_1, summand_2, &result); \ +#define SPECIALIZE_builtin_add_overflow(type, builtin_name) \ + /* Full specialization of builtin_add_overflow for type using the */ \ + /* builtin_name intrinsic */ \ + template <> \ + inline bool builtin_add_overflow(type summand_1, type summand_2, type & result) \ + { \ + return builtin_name(summand_1, summand_2, &result); \ } SPECIALIZE_builtin_add_overflow(int, __builtin_sadd_overflow); @@ -255,11 +255,11 @@ namespace Safe * The intrinsics are documented here: * https://msdn.microsoft.com/en-us/library/windows/desktop/ff516460(v=vs.85).aspx */ -#define SPECIALIZE_builtin_add_overflow_WIN(type, builtin_name) \ - template <> \ - bool builtin_add_overflow(type summand_1, type summand_2, type& result) \ - { \ - return builtin_name(summand_1, summand_2, &result) != S_OK; \ +#define SPECIALIZE_builtin_add_overflow_WIN(type, builtin_name) \ + template <> \ + inline bool builtin_add_overflow(type summand_1, type summand_2, type& result) \ + { \ + return builtin_name(summand_1, summand_2, &result) != S_OK; \ } SPECIALIZE_builtin_add_overflow_WIN(unsigned int, UIntAdd);