[cfe-dev] libc++'s unorderd_map bug?

oroppas oroppas at gmail.com
Mon Jun 13 20:19:18 PDT 2011


Hi,

Both calng++ and g++ with libc++ fail to compile the attached piece of code,
$ clang++ -std=c++0x -stdlib=libc++ unordered_map.cpp

In file included from ./unordered_map.cpp:1:
/usr/include/c++/v1/string:1031:35: error: no type named 'char_type' in
      'Parameter'
    typedef typename traits_type::char_type              value_type;
            ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~

(lots of error messages)


However, it can be compiled against libstdc++
$ calng++ -std=c++0x unordered_map.cpp

I'm not sure if the program conforms strictly to the standard or it's a bug
in libc++.
Any comment will be appreciated.

Thanks,

Ryuta

#include <string>
#include <map>
#include <unordered_map>

class Parameter
{
  public:
    explicit Parameter( bool arg );
    Parameter();
    ~Parameter();

    unsigned int offset;
    bool argument;
};

class PTXKernel
{
  typedef std::map<std::string,Parameter> ParameterMap;

  public:
    PTXKernel( const std::string& name = "" );
    PTXKernel( const PTXKernel& k );
    ~PTXKernel();

    ParameterMap parameters;

    std::string name;
};

class Module
{
  public:
    typedef std::unordered_map< std::string, PTXKernel > KernelMap;

  private:
    KernelMap _kernels;

  public:
    void insertKernel( const PTXKernel& kernel );
};

///////////////////////////////////////////////////////////////////////////////
/

Parameter::Parameter()
{
  offset = 0;
  argument = false;
}

Parameter::~Parameter() { }

Parameter::Parameter( bool arg ) : argument(arg)
{
  offset = 0;
}

/////////////////////////////

PTXKernel::PTXKernel( const std::string& n ) : name(n)
{
  parameters.insert(make_pair(name,Parameter()));
}

PTXKernel::PTXKernel( const PTXKernel& kernel )
{
  name       = kernel.name;
  parameters = kernel.parameters;
}

PTXKernel::~PTXKernel() { }

/////////////////////////////

void Module::insertKernel( const PTXKernel& kernel )
{
  _kernels.insert( std::make_pair(kernel.name,kernel) );
}

/////////////////////////////

int main()
{
  PTXKernel k1( "k1" );
  PTXKernel k2( "k2" );

  Module m;

  m.insertKernel( k1 );
  m.insertKernel( k2 );

  return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110614/c647e675/attachment.html>


More information about the cfe-dev mailing list