Bug #84951 Problem compiling jsonparser.cpp and jsonview.ccp on Slackware (32 bits)
Submitted: 10 Feb 2017 12:41 Modified: 12 Feb 2017 10:01
Reporter: Georgi Sotirov Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Workbench Severity:S2 (Serious)
Version:6.3.9 OS:Linux (Slackware)
Assigned to: CPU Architecture:Any

[10 Feb 2017 12:41] Georgi Sotirov
Description:
I'm having a problem compiling jsonparser.cpp under Slackware Linux 32 bits:

Building CXX object library/base/CMakeFiles/wbbase.dir/jsonparser.cpp.o
jsonparser.cpp: In member function 'JsonParser::JsonValue& JsonParser::JsonArray::at(JsonParser::JsonArray::SizeType)':
jsonparser.cpp:346:79: error: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'JsonParser::JsonArray::SizeType {aka unsigned int}' [-Werror=format=]
       throw std::out_of_range(base::strfmt("Index '%lu' is out of range.", pos));
                                                                               ^
jsonparser.cpp: In member function 'const JsonParser::JsonValue& JsonParser::JsonArray::at(JsonParser::JsonArray::SizeType) const':
jsonparser.cpp:361:79: error: format '%lu' expects argument of type 'long unsigned int', but argument 2 has type 'JsonParser::JsonArray::SizeType {aka unsigned int}' [-Werror=format=]
       throw std::out_of_range(base::strfmt("Index '%lu' is out of range.", pos));
                                                                               ^
jsonparser.cpp: In member function 'void JsonParser::JsonWriter::write(const JsonParser::JsonValue&)':
jsonparser.cpp:1672:44: error: conversion from 'const JsonParser::JsonValue' to 'int64_t {aka long long int}' is ambiguous
         _output += std::to_string((int64_t)value);
                                            ^
cc1plus: all warnings being treated as errors
...
Building CXX object library/forms/CMakeFiles/mforms.dir/jsonview.cpp.o
jsonview.cpp: In member function 'void mforms::JsonTreeBaseView::setCellValue(mforms::TreeNodeRef, int, const string&)':
jsonview.cpp:672:21: error: ambiguous overload for 'operator=' (operand types are 'JsonParser::JsonValue' and 'int64_t {aka long long int}')
         storedValue = number2;
                     ^
jsonview.cpp:680:21: error: ambiguous overload for 'operator=' (operand types are 'JsonParser::JsonValue' and 'uint64_t {aka long long unsigned int}')
         storedValue = number3;
                     ^
jsonview.cpp: In member function 'virtual void mforms::JsonTreeView::generateNumberInTree(JsonParser::JsonValue&, int, mforms::TreeNodeRef)':
jsonview.cpp:1077:51: error: conversion from 'JsonParser::JsonValue' to 'int64_t {aka long long int}' is ambiguous
       node->set_string(1, std::to_string((int64_t)value));
                                                   ^
jsonview.cpp:1081:52: error: conversion from 'JsonParser::JsonValue' to 'uint64_t {aka long long unsigned int}' is ambiguous
       node->set_string(1, std::to_string((uint64_t)value));
                                                    ^
jsonview.cpp: In member function 'void mforms::JsonGridView::setCellValue(mforms::TreeNodeRef, int, const string&)':
jsonview.cpp:1342:21: error: ambiguous overload for 'operator=' (operand types are 'JsonParser::JsonValue' and 'int64_t {aka long long int}')
         storedValue = number2;
                     ^
jsonview.cpp:1351:21: error: ambiguous overload for 'operator=' (operand types are 'JsonParser::JsonValue' and 'uint64_t {aka long long unsigned int}')
         storedValue = number3;
                     ^
jsonview.cpp: In member function 'virtual void mforms::JsonGridView::generateNumberInTree(JsonParser::JsonValue&, int, mforms::TreeNodeRef)':
jsonview.cpp:1615:41: error: conversion from 'JsonParser::JsonValue' to 'int64_t {aka long long int}' is ambiguous
       node->set_long(columnId, (int64_t)value);
                                         ^
jsonview.cpp:1618:42: error: conversion from 'JsonParser::JsonValue' to 'uint64_t {aka long long unsigned int}' is ambiguous
       node->set_long(columnId, (uint64_t)value);
                                          ^
library/forms/CMakeFiles/mforms.dir/build.make:1910: recipe for target 'library/forms/CMakeFiles/mforms.dir/jsonview.cpp.o' failed

(The full log would be provided as attachment)

*Note*: There is no such problem at all on Slackware Linux 64 bits.

How to repeat:
1. Download mysql-workbench-community-6.3.9-src.tar.gz;
2. Unpack and configure like this:

ANTLR_JAR_PATH="/usr/lib/antlr-3.4-complete.jar" \
cmake \
    -DCMAKE_C_FLAGS:STRING="-O3 -march=i586 -mtune=i686 -DTIXML_USE_STL" \
    -DCMAKE_CXX_FLAGS:STRING="-O3 -march=i586 -mtune=i686 -std=c++11 -DTIXML_USE_STL" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLIB_INSTALL_DIR=/usr/lib \
    -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python2.7 \
    -DPYTHON_LIBRARY:FILEPATH=/usr/lib/libpython2.7.so \
    -DGDAL_INCLUDE_DIR=/usr/include \
    -DCMAKE_BUILD_TYPE=Release

3. Try building with: make VERBOSE=1

Suggested fix:
The following patch resolves the compilation issues, but I'd like it to be reviewed upstream, because I'm really not that familiar with the source:

diff -urNad mysql-workbench-community-6.3.9-src-orig/library/base/jsonparser.cpp mysql-workbench-community-6.3.9-src/library/base/jsonparser.cpp
--- mysql-workbench-community-6.3.9-src-orig/library/base/jsonparser.cpp	2017-02-03 20:40:18.000000000 +0200
+++ mysql-workbench-community-6.3.9-src/library/base/jsonparser.cpp	2017-02-10 10:35:12.193163967 +0200
@@ -343,7 +343,7 @@
    */
   JsonValue &JsonArray::at(SizeType pos) {
     if (pos > _data.size())
-      throw std::out_of_range(base::strfmt("Index '%lu' is out of range.", pos));
+      throw std::out_of_range(base::strfmt("Index '%zu' is out of range.", pos));
     return _data.at(pos);
   }
 
@@ -358,7 +358,7 @@
    */
   const JsonValue &JsonArray::at(SizeType pos) const {
     if (pos > _data.size())
-      throw std::out_of_range(base::strfmt("Index '%lu' is out of range.", pos));
+      throw std::out_of_range(base::strfmt("Index '%zu' is out of range.", pos));
     return _data.at(pos);
   }
 
@@ -1669,10 +1669,10 @@
         _output += std::to_string((double)value);
         break;
       case VInt64:
-        _output += std::to_string((int64_t)value);
+        _output += std::to_string((ssize_t)value);
         break;
       case VUint64:
-        _output += std::to_string((uint64_t)value);
+        _output += std::to_string((size_t)value);
         break;
       case VObject:
         write((JsonObject)value);
diff -urNad mysql-workbench-community-6.3.9-src-orig/library/forms/jsonview.cpp mysql-workbench-community-6.3.9-src/library/forms/jsonview.cpp
--- mysql-workbench-community-6.3.9-src-orig/library/forms/jsonview.cpp	2017-02-03 20:40:18.000000000 +0200
+++ mysql-workbench-community-6.3.9-src/library/forms/jsonview.cpp	2017-02-10 12:11:35.705698768 +0200
@@ -651,8 +651,8 @@
   if (data != nullptr) {
     std::stringstream buffer;
     double number = 0;
-    int64_t number2 = 0;
-    uint64_t number3 = 0;
+    ssize_t number2 = 0;
+    size_t number3 = 0;
     bool retBool = false;
     auto &storedValue = data->getData();
     switch (storedValue.getType()) {
@@ -1074,11 +1074,11 @@
       node->set_string(2, "Double");
       break;
     case VInt64:
-      node->set_string(1, std::to_string((int64_t)value));
+      node->set_string(1, std::to_string((ssize_t)value));
       node->set_string(2, "Long Integer");
       break;
     case VUint64:
-      node->set_string(1, std::to_string((uint64_t)value));
+      node->set_string(1, std::to_string((size_t)value));
       node->set_string(2, "Unsigned Long Integer");
       break;
     default:
@@ -1322,8 +1322,8 @@
   if (data != NULL) {
     std::stringstream buffer;
     double number = 0;
-    int64_t number2 = 0;
-    uint64_t number3 = 0;
+    ssize_t number2 = 0;
+    size_t number3 = 0;
     bool retBool = false;
     switch (storedValue.getType()) {
       case VDouble:
@@ -1612,10 +1612,10 @@
       node->set_float(columnId, (double)value);
       break;
     case VInt64:
-      node->set_long(columnId, (int64_t)value);
+      node->set_long(columnId, (ssize_t)value);
       break;
     case VUint64:
-      node->set_long(columnId, (uint64_t)value);
+      node->set_long(columnId, (size_t)value);
       break;
     default:
       break;
[10 Feb 2017 12:43] Georgi Sotirov
Detailed build errors log

Attachment: wb-6.3.9-build_errors_slk_14.2-32b.txt (text/plain), 19.96 KiB.

[10 Feb 2017 12:45] Georgi Sotirov
Suggested patch

Attachment: wb-6.3.9-json_patch.diff (application/octet-stream, text), 3.27 KiB.

[12 Feb 2017 10:01] Mike Lischke
Note: there is a patch pending for this problem (see bug #84886).