This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/66AK2H12: Compiler C6000 8.2.1 hash_set issue

Part Number: 66AK2H12

Tool/software: TI C/C++ Compiler

Hi

I wrote the following code:

#include <hash_set>

struct X
{

};

typedef std::hash_set<X*, std::hash<X*>,std::equal_to<X*>,
std::allocator<X*> > AllocatedBlocksSet;
AllocatedBlocksSet t;


typedef std::hash_set<void*, std::hash<void*>,std::equal_to<void*>,
std::allocator<void*> > VoidPtrBlocksSet;
VoidPtrBlocksSet t1;

void func()
{
X* ret;
t.insert(ret);
}

void func1()
{
X* ret;
t1.insert((void*)ret);
}

func() fails with the following error: "C:/ti/ccsv6/tools/compiler/c6000_8.2.1/include/s__hashtable.h", line 617: error #1034: call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type

func1 doesn't fail

X* and void* are both pointers so why does one compile and the other doesn't

Thanks

Shiran

  • The TI compiler currently supports the C++ standard from 1998/2003 (C++98/03).

    std::hash and std::hash_set are not part of this standard, and are provided as non-portable extensions to the standard library.

    Our extension version of std::hash, in particular, has the following relevant specializations:

    template <class _Key> struct hash { };

    struct hash<char*> // defines operator()

    struct hash<const char*> // defines operator()

    struct hash<void *> // defines operator()

    Note that the default instantiation has no operator() to call.


    Your sample code generates a std::hash<X*>, which does not fit into any of the defined specializations. This causes the default specialization to be used, and the underlying hash_set implementation to fail because there's no operator() it can use to hash the pointers.

    I suggest that you use std::hash<void*> to hash X* objects. Alternatively, you can define your own std::hash specialization like this:

    namespace std {
      template<> struct hash<X*> {
        size_t operator()(X *val) const {
          return (size_t)val;
        }
      };
    }