2 Replies Latest reply: Nov 30, 2011 5:48 AM by koval RSS

    Problem while compiling the templates.

      Hi All,

      By looking at the Tools.h++ files, i tried to mimic RWTValHashMap.

      The following example is working fine with gcc but CC compiler reports the following error.
      #include <iostream>
      #include <string>
      #include "RWTValHashMap.h"
      struct silly_h{
         unsigned long operator()(const std::string& x) const
         { return x.length() * (long)x[0]; }
      int main(){
         RWTValHashMap <std::string, std::string, silly_h, std::equal_to<std::string> > age;
         RWTValHashMapIterator <std::string, std::string, silly_h, std::equal_to<std::string> > itr(age);
         age.insert(std::string("John"), std::string("30"));
         age.insert(std::string("Steve"), std::string("17"));
         age.insert(std::string("Mark"), std::string("24"));
      //Duplicate insertion rejected
         age.insert(std::string("Steve"), std::string("24"));
           std::cout << itr.key() << "\'s age is " << itr.value() << std::endl;
         return 0;
      $ g++ -m32 -Wall -g test.cc -o test
      $ ./test
      John's age is 30
      Steve's age is 17
      Mark's age is 24
      $ CC -m32 -g -library=stlport4 test.cc -o test
      "RWTValHashMap.h", line 270: Error: int is not a structure type.
      "test.cc", line 23:     Where: While instantiating "RWTValHashMapIterator<std::string, std::string, silly_h, std::equal_to<std::string>>::key() const".
      "test.cc", line 23:     Where: Instantiated from non-template code.
      1 Error(s) detected.
      There are 5 files required for "RWTValHashMap".
      Pasting all of the files here bloats the post.
      Hence sharing the zip file. (Could not find any attachment-option here, hence sharing through external server)


      Also i have tried to mimic the scenario with a small program (replicate_problem.cc [present in the attachment]), but no luck.
      The program works fine with both gcc and CC.

      Please help me in finding out the exact problem:
      - whether it is in my version of "RWTValHashMap".
      - am i missing some options required.
      - limitation of solaris CC compiler.


      Edited by: 855323 on Jun 7, 2011 2:13 PM
        • 1. Re: Problem while compiling the templates.
          The problem looks like a bug in the compiler. If you have an Oracle service contract, please file a bug report via your support channel. You will be kept informed about progress, the support personnel will try to find a workaround for you, and you will have early access to a patch that fixes the problem.

          Otherwise, you can file a bug report on c++/compiler at http://bugs.sun.com
          We'll try to fix the bug in the next compiler release. There is no way to attach files to the bug report, but you can provide a pointer to the same zip file you referenced here.
          • 2. Re: Problem while compiling the templates.
            I thinks this is because of wrong <tt>HashTable::Iterator definition</tt>
            You have
            class Iterator : public std::iterator <T, difference_type>
            You missed <tt>Category</tt> parameter of <tt>std::iterator</tt>, its declaration reads:
            template<class Category, class T, class Distance = ptrdiff_t, class Pointer = T*, class Reference = T&> struct iterator;
            Here, <tt>T</tt> is taken as category and <tt>difference_type</tt> (which is integer) as the value type (<tt>T</tt>)
            simply change to
            class Iterator : public std::iterator<std::forward_iterator_tag, T, difference_type>