0

I have something similar to this:

//file1.h
class Base {

private:
    static std::unordered_map<int, std::unordered_map<int, std::string>> table;
}

And to make everything work as expect I write this:

//file1.cpp
std::unordered_map<int, std::unordered_map<int, std::string>> Base::table = {
    {
      1, std::unordered_map<int, std::string> { 
           {12, "asset:12/"},
           {-3, "asset:24/"},
           //...
         }
    },
     //...
};  

I use visual studio 2017 latest update (15.8.5) and this code fails:

//file1.h
class Base {

private:
    inline static std::unordered_map<int, std::unordered_map<int, std::string>> table = {
        {
          1, std::unordered_map<int, std::string> { 
               {12, "asset:12/"},
               {-3, "asset:24/"},
               //...
             }
        },
         //...
    };  

Why does this inline declaration fail? I have seen that since C++17 you can have inline static declarations. The problem is in the list header and it states:

**_Pnode** was 0xDDDDDDDD.

Is it a problem with maps? I have run the code in coliru and I didn't have the issue that I've found in VS. Screen:

enter image description here

The output dialog is:

The thread 0x3790 has exited with code 0 (0x0). Exception thrown: read access violation. _Pnode was 0xDDDDDDDD.

Exit code is 0 but I don't understand where the access violation could happen.

Raffaele Rossi
  • 2,997
  • 4
  • 31
  • 62
  • 2
    0xDDDDDDDD : Used by Microsoft's C++ debugging heap to mark freed heap memory https://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations – drescherjm Sep 25 '18 at 22:56
  • See my updated question @drescherjm! – Raffaele Rossi Sep 25 '18 at 22:59
  • is that all code you have? It really possible that MS got defects in implementation. coliru uses some unnamed build of g++, it's not fully compatible with cl... if you want particular version of GCC or clang, use wandbox or similar, they allow to choose and report which build they use. – Swift - Friday Pie Sep 25 '18 at 23:07
  • 3
    There are too many open possibilities here, not the least of which is bug elsewhere being exposed here. Could we trouble you for an [mcve]? – user4581301 Sep 25 '18 at 23:18
  • you free'd something then tried to use it. Most likely, you are in UB land and one implementation seemed to work and in the MS one the debug heap forced a clearer behavior – pm100 Sep 25 '18 at 23:25
  • I am voting to close because the code you show works for me on VS15.9.5. – Werner Henze Jan 14 '19 at 19:50

0 Answers0