C++11 Compiling error on Windows

Bug #1070998 reported by Rodolfo Ochoa
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zorba
Fix Released
Critical
Markos Zaharioudakis

Bug Description

since new version of MS C++ Compiler is closer to C++11 standard, Windows is failing to compile due a bug in
 src/unit_tests/test_hashmaps.cpp
where a hash is created with zstring as key

Changed in zorba:
assignee: nobody → Rodolfo Ochoa (rodolfo-ochoa)
Changed in zorba:
assignee: Rodolfo Ochoa (rodolfo-ochoa) → Paul J. Lucas (paul-lucas)
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

It would help if you included the error message.

Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) wrote :

The error code doesn't say much:

Error 2 error C2338: The C++ Standard doesn't provide a hash for this type. (..\..\src\unit_tests\test_hashmaps.cpp) C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstddef 238 1 zorba_simplestore

but the error is on src\unit_tests\test_hashmaps.cpp:97:
std::unordered_map<zstring, int> map4(1024);

instead of zstring should be a primitive type.
std:string is allowed, but I think this will not fulfill the purpose of the test.

Revision history for this message
Chris Hillery (ceejatec) wrote :

This is preventing the trunk from compiling on Windows (at least with the latest compiler), so bumping the priority. Paul, please try to propose some solution ASAP.

Changed in zorba:
milestone: none → 2.8
importance: Undecided → Critical
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

Markos wrote the test_hashmaps.cpp file, not me. For *my* unit test file test_unordered_map.cpp, I correctly do *not* compile it if the C++ implementation provides its own unordered map.

This is Markos' bug, not mine.

Changed in zorba:
assignee: Paul J. Lucas (paul-lucas) → Markos Zaharioudakis (markos-za)
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

Despite that, try adding:

#include "util/hash/hash.h"
#include "zorbatypes/zstring.h"

to the list of include files in test_hashmaps.cpp. I have no way to test this myself.

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

The other fix is simply not to use zstring and use std::string instead. He's presumably testing the hashmaps, not strings, so any string will do.

Revision history for this message
Chris Hillery (ceejatec) wrote :

This problem was introduced by change 11091 from Markos "Hashmap optimizations". (I still think Paul is probably the best person to look at it, but if Markos has a chance since Paul is out for the next week that would be good.)

I have pushed a branch which works around this problem by disabling test_hashmap:

  https://code.launchpad.net/~zorba-coders/zorba/windows-hashmap-workaround/+merge/131716

Revision history for this message
Chris Hillery (ceejatec) wrote :

Unfortunately Paul's suggestion in comment #5 doesn't fix it. The error changes to

test_hashmaps.cpp
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(94) : error C2146: syntax error : missing ';' before identifier 't0'
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(94) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(95) : error C2146: syntax error : missing ';' before identifier 't1'
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(95) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(113) : error C2146: syntax error : missing ';' before identifier 'get_registration_time'
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(113) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(113) : warning C4183: 'get_registration_time': missing return type; assumed to be a member function returning 'int'
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(113) : error C2065: 't1' : undeclared identifier
C:\zorba\trunk\src\zorbaserialization/class_serializer.h(113) : error C2065: 't0' : undeclared identifier
C:\zorba\trunk\src\unit_tests\test_hashmaps.cpp(32) : warning C4244: 'return' : conversion from 'uint64_t' to 'uint32_t', possible loss of data
C:\zorba\trunk\src\unit_tests\test_hashmaps.cpp(101) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
C:\zorba\trunk\src\unit_tests\test_hashmaps.cpp(102) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
NMAKE : fatal error U1077: 'C:\PROGRA~2\MICROS~2.0\VC\bin\cl.exe' : return code '0x2'
Stop.

Revision history for this message
Chris Hillery (ceejatec) wrote :

Actually that appears to be the same error message as without Paul's suggestion.

Revision history for this message
Chris Hillery (ceejatec) wrote :

Even with my workaround, there are a number of compilation warnings that I do not believe were there prior to Markos' change. eg:

[ 21%] Building CXX object src/CMakeFiles/zorba_simplestore.dir/store/naive/store.cpp.obj
store.cpp
C:\zorba\trunk\src\zorbautils/hashmap.h(827) : warning C4244: 'return' : conversion from 'const double' to 'zorba::csize', possible loss of data
        C:\zorba\trunk\src\zorbautils/hashmap.h(826) : while compiling class template member function 'zorba::csize zorba::HashMap<T,V,C>::computeCapacity(zorba::csize) const'
        with
        [
            T=zorba::zstring,
            V=zorba::simplestore::XmlNode_t,
            C=zorba::HashMapZStringCmp
        ]
        C:\zorba\trunk\src\zorbautils/hashmap.h(395) : see reference to function template instantiation 'zorba::csize zorba::HashMap<T,V,C>::computeCapacity(zorba::csize) const' being compiled
        with
        [
            T=zorba::zstring,
            V=zorba::simplestore::XmlNode_t,
            C=zorba::HashMapZStringCmp
        ]
        c:\zorba\trunk\src\store\naive\store.h(181) : see reference to class template instantiation 'zorba::HashMap<T,V,C>' being compiled
        with
        [
            T=zorba::zstring,
            V=zorba::simplestore::XmlNode_t,
            C=zorba::HashMapZStringCmp
        ]

This leads me to believe there is a template-related error somewhere, which is why I think Paul is probably the best victim here.

Revision history for this message
Markos Zaharioudakis (markos-za) wrote :

The warnings from HashMap are easy to fix, and I will fix them in my next chakin. However, if zstring cannot be used as a key for std::unordered_map, that is Paul's problem, not mine. Or maybe zstring can be used as a key, but I am doing something wrong or incomplete in my code. However, if this is the case, I don't know what it is that I am doing wrong, so I would again ask Paul's help to fix it. So, I am reassigning this to Paul.

Changed in zorba:
assignee: Markos Zaharioudakis (markos-za) → Paul J. Lucas (paul-lucas)
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

zstring can be used as a key, however, you didn't #include the file where the hash for zstring is in fact defined: util/hash/hash.h. Only #include'ing "unordered_map.h" is insufficient.

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

Also, as I originally said: you're presumably testing hashmaps, not zstrings, so there's no compelling reason for you to use zstring (as oppose to std::string) in your test.

Changed in zorba:
assignee: Paul J. Lucas (paul-lucas) → Markos Zaharioudakis (markos-za)
Changed in zorba:
status: New → Fix Committed
Changed in zorba:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.