]> granicus.if.org Git - re2c/commitdiff
Don't use overloaded constructors with integral types.
authorUlya Trofimovich <skvadrik@gmail.com>
Sat, 28 Nov 2015 11:36:41 +0000 (11:36 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Sat, 28 Nov 2015 11:36:41 +0000 (11:36 +0000)
This causes ambiguity in overload resolution on OS X:

    src/codegen/skeleton/generate_data.cc:308:30: error: ambiguous conversion for functional-style cast from 'const size_t' (aka 'const unsigned long') to 'Node::covers_t'
          (aka 'u32lim_t<1024 * 1024 * 1024>')
            const Node::covers_t size = Node::covers_t (len) * Node::covers_t (count);
                                        ^~~~~~~~~~~~~~~~~~~
    ./src/util/u32lim.h:20:11: note: candidate constructor
            explicit u32lim_t (uint32_t x)
                     ^
    ./src/util/u32lim.h:23:11: note: candidate constructor
            explicit u32lim_t (uint64_t x)

Use static constructor-like methods with expliit names.

re2c/src/codegen/skeleton/control_flow.cc
re2c/src/codegen/skeleton/generate_data.cc
re2c/src/util/u32lim.h

index e5fa3fe314f56b5f9b1439278087a6f9b31d324f..976740eb376b25a89dd81345058cfdca74ad593e 100644 (file)
@@ -10,17 +10,17 @@ Node::nakeds_t Node::naked_ways (const way_t & prefix, std::vector<way_t> & ways
 {
        if (!rule.rank.is_none ())
        {
-               return nakeds_t (0u);
+               return nakeds_t::from32(0u);
        }
        else if (end ())
        {
                ways.push_back (prefix);
-               return nakeds_t (prefix.size ());
+               return nakeds_t::from64(prefix.size ());
        }
        else if (loop < 2)
        {
                local_inc _ (loop);
-               nakeds_t size (0u);
+               nakeds_t size = nakeds_t::from32(0u);
                for (arcsets_t::iterator i = arcsets.begin (); i != arcsets.end (); ++i)
                {
                        way_t w = prefix;
@@ -35,7 +35,7 @@ Node::nakeds_t Node::naked_ways (const way_t & prefix, std::vector<way_t> & ways
        }
        else
        {
-               return nakeds_t (0u);
+               return nakeds_t::from32(0u);
        }
 }
 
index 2faf76e267acf0fbf05d633c4df3d743df6bb467..db780b7551b3e1116642216f8fd84d58acec9bc3 100644 (file)
@@ -58,11 +58,11 @@ Node::permuts_t Node::sizeof_permutate (permuts_t wid, permuts_t len)
        else if (loop < 2)
        {
                local_inc _ (loop);
-               permuts_t size (0u);
-               const permuts_t new_len = len + permuts_t (1u);
+               permuts_t size = permuts_t::from32(0u);
+               const permuts_t new_len = len + permuts_t::from32(1u);
                for (arcs_t::iterator i = arcs.begin (); i != arcs.end (); ++i)
                {
-                       const permuts_t new_wid = wid * permuts_t (i->second.size ());
+                       const permuts_t new_wid = wid * permuts_t::from64(i->second.size ());
                        if (new_wid.overflow ())
                        {
                                return permuts_t::limit ();
@@ -77,7 +77,7 @@ Node::permuts_t Node::sizeof_permutate (permuts_t wid, permuts_t len)
        }
        else
        {
-               return permuts_t (0u);
+               return permuts_t::from32(0u);
        }
 }
 
@@ -145,7 +145,7 @@ template <typename cunit_t, typename key_t>
 template <typename cunit_t, typename key_t>
        Node::covers_t Node::cover (const multipath_t & prefix, FILE * input, FILE * keys)
 {
-       covers_t size (0u);
+       covers_t size = covers_t::from32(0u);
        if (end () && suffix == NULL)
        {
                suffix = new path_t (rule, ctx);
@@ -180,7 +180,7 @@ template <typename cunit_t, typename key_t>
        void Skeleton::generate_paths_cunit_key (FILE * input, FILE * keys)
 {
        multipath_t prefix (nodes->rule, nodes->ctx);
-       if (nodes->sizeof_permutate (Node::permuts_t (1u), Node::permuts_t (0u)).overflow ())
+       if (nodes->sizeof_permutate (Node::permuts_t::from32(1u), Node::permuts_t::from32(0u)).overflow ())
        {
                if (nodes->cover<cunit_t, key_t> (prefix, input, keys).overflow ())
                {
@@ -305,7 +305,7 @@ template <typename cunit_t, typename key_t>
                count = std::max (count, prefix[i]->size ());
        }
 
-       const Node::covers_t size = Node::covers_t (len) * Node::covers_t (count);
+       const Node::covers_t size = Node::covers_t::from64(len) * Node::covers_t::from64(count);
        if (!size.overflow ())
        {
                // input
index bda1784ad5c914468b39b797693965338b5f11a4..d9c356ccfa5f140c9c064eb665806c974efb1fd4 100644 (file)
@@ -11,12 +11,6 @@ template<uint32_t LIMIT>
 class u32lim_t
 {
        uint32_t value;
-
-public:
-       // implicit conversion is forbidden, because
-       // operands should be converted before operation:
-       //     uint32_t x, y; ... u32lim_t z = x + y;
-       // will result in 32-bit addition and may overflow
        explicit u32lim_t (uint32_t x)
                : value (x < LIMIT ? x : LIMIT)
        {}
@@ -24,6 +18,16 @@ public:
                : value (x < LIMIT ? static_cast<uint32_t> (x) : LIMIT)
        {}
 
+public:
+       // implicit conversion is forbidden, because
+       // operands should be converted before operation:
+       //     uint32_t x, y; ... u32lim_t z = x + y;
+       // will result in 32-bit addition and may overflow
+       // Don't export overloaded constructors: it breaks OS X builds
+       // ('size_t' causes resolution ambiguity)
+       static u32lim_t from32 (uint32_t x) { return u32lim_t(x); }
+       static u32lim_t from64 (uint64_t x) { return u32lim_t(x); }
+
        static u32lim_t limit ()
        {
                return u32lim_t (LIMIT);