From f348522005fc3b33b2aa8de9aa27f3a203a56dad Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 18 Aug 2018 16:37:47 +0200 Subject: [PATCH] C++: fix portability issue with MSVC 2017 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Visual Studio issues a C4146 warning on '-static_cast(rhs)'. The code is weird, probably to cope with INT_MIN. Let's go back to using std::max (whose header is still included in position.hh...) like originally, but with the needed casts. Reported by 長田偉伸, and with help from Rici Lake. See also http://lists.gnu.org/archive/html/bug-bison/2013-02/msg00000.html and commit 75ae8299840bbd854fa2474d38402bbb933c6511. * data/location.cc (position::add_): Take min as an int. Use std::max. While here, get rid of a couple of useless inlines. --- THANKS | 1 + data/location.cc | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/THANKS b/THANKS index 93e72fe1..48b4ec85 100644 --- a/THANKS +++ b/THANKS @@ -172,6 +172,7 @@ Wolfram Wagner ww@mpi-sb.mpg.de Wwp subscript@free.fr xolodho xolodho@gmail.com Zack Weinberg zack@codesourcery.com +長田偉伸 cbh34680@iret.co.jp Many people are not named here because we lost track of them. We thank them! Please, help us keeping this list up to date. diff --git a/data/location.cc b/data/location.cc index 3cc949df..07f1ca62 100644 --- a/data/location.cc +++ b/data/location.cc @@ -73,12 +73,10 @@ m4_define([b4_position_define], unsigned column; private: - /// Compute max(min, lhs+rhs) (provided min <= lhs). - static unsigned add_ (unsigned lhs, int rhs, unsigned min) + /// Compute max(min, lhs+rhs). + static unsigned add_ (unsigned lhs, int rhs, int min) { - return (0 < rhs || -static_cast(rhs) < lhs - ? rhs + lhs - : min); + return static_cast(std::max(min, static_cast(lhs) + rhs)); } }; @@ -134,7 +132,7 @@ m4_define([b4_position_define], ** \param pos a reference to the position to redirect */ template - inline std::basic_ostream& + std::basic_ostream& operator<< (std::basic_ostream& ostr, const position& pos) { if (pos.filename) @@ -271,7 +269,7 @@ m4_define([b4_location_define], ** Avoid duplicate information. */ template - inline std::basic_ostream& + std::basic_ostream& operator<< (std::basic_ostream& ostr, const location& loc) { unsigned end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;