VC2019: Compiler Bug, std::pair Bug or Obscure Feature

Viewed 70

The code below crashes the application or prints gibberish. If the initialization of the base class is replaced with str_int{ string{V}, 0} then it works fine. Seems to work fine with some online compilers.

#include <iostream>
#include <utility>

using namespace std;

using str_int = pair<string, int>;

template< const char* V > 
struct C : public str_int
{
  C() : str_int{ V, 0} {}
};

constexpr const char str[] = "abc";

int main()
{
  // works fine
  str_int si{str, 0};
  cout << si.first;

  // crashes the application or prints gibberish
  C<str> c;
  cout << c.first;
}
0 Answers
Related