1

I've reduced my case as much as possible below.

#include <vector>
#include <atomic>
#include <chrono>

using namespace std;

class Unused
{
  private:

    vector<vector<unsigned>> data;
    atomic<unsigned> counter;
};

class Timer
{
  private:

    chrono::time_point<chrono::high_resolution_clock> begin;

  public:

    void start()
    {
      begin = std::chrono::high_resolution_clock::now();
    }

};

int main()
{
  Unused unused;

  vector<Timer> timers;
  timers.resize(1);
  timers[0].start();
}

I've compiled it as (note the specific flags):

cl /O2 /GL /EHsc driver.cpp

This is with

Microsoft (R) C/C++-Optimierungscompiler Version 19.27.29111 für x86
Microsoft (R) Incremental Linker Version 14.27.29111.0

but I've tried a couple of other recent versions as well. The executable segfaults with a memory access violation. It works with g++, and it works if I change the compile flags. It also works is I simplify the code further.

Is this a compiler bug?

1 Answers1