IBM Support

IV02851: UNORDERED_MAP CALLING INCORRECT CONSTRUCTOR

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • For the following test case, the default
    constructor gets called when it should have called the correct
    constructor that took in two params.
    
    The test case has this allocator class that requires a
    constructor with one parameter. It declares the default
    constructor as private to ensure it is never called.
    Then, the test case creates an unordered_map using that
    allocator. So they instantiate the unordered map using that
    allocator class, but when it constructs the unordered_map
    object, the test case passes an explicitly constructed allocator
    object to the unordered_map constructor.
    
    ===== COMPILE COMMAND:
    xlC vector.C -D__IBMCPP_TR1__=1
    
    ===== TESTCASE:
    $ cat vector.C
    #include <stdlib.h>
    #include <stdio.h>
    
    
    #include <vector>
    #ifdef __GNUC__
    #include <tr1/unordered_map>
    #else
    #include <unordered_map>
    #endif
    
    template <class U>
    class alloc {
    private:
        alloc() { printf("private cons %x\n", (long) this);}
    public:
      alloc(int x) { printf("public cons %x: %d\n", (long) this,
    x);}
    
      template <class UU>
      alloc(const alloc<UU> &A) { }
    
      template <class UU> struct rebind {
        typedef alloc<UU> other;
      };
      typedef size_t size_type;
      typedef ptrdiff_t difference_type;
      typedef U *pointer;
      typedef const U *const_pointer;
      typedef U &reference;
      typedef const U &const_reference;
      typedef U value_type;
      pointer address(reference x) const;
      const_pointer address(const_reference x) const;
    
      template <class UU>
      pointer allocate( size_type elements, const UU* base) {
        return (pointer)malloc(elements);
      }
    
      pointer allocate( size_type elements) {
        return (pointer)malloc(elements);
      }
    
      void deallocate( pointer addr, size_type n) {
        free(addr);
      }
    
      void construct(pointer p, const U& val) {
        new ((void *)p) U(val);
      }
    
      void destroy( pointer addr) {
      }
      size_type max_size() const { return 1000000000;}
    
    private:
    };
    
    int main() {
    
      std::tr1::hash<unsigned> h;
      std::equal_to<unsigned> e;
      alloc<std::pair<const unsigned, unsigned> >a(1);
    
      std::tr1::unordered_map<unsigned, unsigned,
    std::tr1::hash<unsigned>, std::equal_to<unsigned>,
    alloc<std::pair<const unsigned, unsigned> > > m(3,h,e,a);
    
    }
    
    $
    
    ===== ACTUAL OUTPUT:
    $ ./a.out
    public cons 2ff227f0: 1
    private cons 2ff226b0
    private cons 2ff226c0
    $
    
    
    ===== EXPECTED OUTPUT:
    $ ./a.out
    public cons ffbde0fa: 1
    $
    

Local fix

  • n/a
    

Problem summary

  • USERS AFFECTED:
    Users using TR1 unordered_map with allocators expecting that
    allocator arguments are honoured are affected by this issue.
    
    PROBLEM DESCRIPTION:
    unordered_map may cause default construction of allocators
    despite provided allocator argument.
    

Problem conclusion

  • The allocator argument is now passed to constructors for
    subobjects of unordered_map.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV02851

  • Reported component name

    XL C FOR AIX

  • Reported component ID

    5724X1200

  • Reported release

    B10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2011-07-05

  • Closed date

    2011-10-26

  • Last modified date

    2011-10-26

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

    LI76458

Fix information

  • Fixed component name

    XL C++ RUNTIME

  • Fixed component ID

    5724X1301

Applicable component levels

  • RB10 PSY U848515

       UP C

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"11.1","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
26 October 2011