bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: position.hh compile error C4146 (VisualStudio 2017)


From: Akim Demaille
Subject: Re: position.hh compile error C4146 (VisualStudio 2017)
Date: Sat, 18 Aug 2018 16:45:29 +0200

Please keep address@hidden

> Le 18 août 2018 à 15:53, 長田偉伸 <address@hidden> a écrit :
> 
> it is still broken.
> 
>> Can I install this fix?
> 
>> Would you also consider reporting this bug to MS?
> 
> Sorry, I can not do anything.
> 
> Because I can understand English only a little.
> (I am Japanese)

That’s fine :)

The code was actually stupid.  Please try this.  Thanks!

commit d32b0c7ee5d39bd33589fc5e62985a68ab78087e
Author: Akim Demaille <address@hidden>
Date:   Sat Aug 18 16:37:47 2018 +0200

    C++: fix portability issue with MSVC 2017
    
    Visual Studio dies with parse error on '-static_cast<unsigned>(rhs)'.
    But the code
    
        return (0 < rhs || -static_cast<unsigned>(rhs) < lhs
                ? rhs + lhs
                : min);
    
    was really all wrong, it should have been
    
        return (0 < rhs || static_cast<unsigned>(-rhs) < lhs
                ? rhs + lhs
                : min);
    
    yet let's go back to using std::max (whose header is still included in
    position.hh...) like originally, but with all the needed casts.
    
    Reported by 長田偉伸.
    
    See also
    http://lists.gnu.org/archive/html/bug-bison/2013-02/msg00000.html
    and commit 75ae8299840bbd854fa2474d38402bbb933c6511.
    
    * data/location.cc (position::add_): Use std::max.

diff --git a/THANKS b/THANKS
index 33f23ed7..c655e3c6 100644
--- a/THANKS
+++ b/THANKS
@@ -173,6 +173,7 @@ Wolfram Wagner            address@hidden
 Wwp                       address@hidden
 xolodho                   address@hidden
 Zack Weinberg             address@hidden
+長田偉伸                   address@hidden
 
 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..622ffd61 100644
--- a/data/location.cc
+++ b/data/location.cc
@@ -73,12 +73,11 @@ m4_define([b4_position_define],
     unsigned column;
 
   private:
-    /// Compute max(min, lhs+rhs) (provided min <= lhs).
+    /// Compute max(min, lhs+rhs).
     static unsigned add_ (unsigned lhs, int rhs, unsigned min)
     {
-      return (0 < rhs || -static_cast<unsigned>(rhs) < lhs
-              ? rhs + lhs
-              : min);
+      return static_cast<unsigned>(std::max(static_cast<int>(min),
+                                            static_cast<int>(lhs) + rhs));
     }
   };
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]