0

according to cplusplus.com on std::bad_alloc

Type of the exceptions thrown by the standard definitions of operator new and operator new[] when they fail to allocate the requested storage space.

However, in my code the new operator is not used:

#include <iostream>
#include <boost/filesystem.hpp>
#include <cstdint>

using namespace std;
using namespace boost::filesystem;

int main()
{
  path p{};

  std::cin >> p;

  if (exists(p))    // does p actually exist?
  {
    if (is_regular_file(p))        // is p a regular file?
      cout << p << " size is " << file_size(p) << '\n';

    else if (is_directory(p))      // is p a directory?
      cout << p << "is a directory\n";

    else
      cout << p << "exists, but is neither a regular file nor a directory\n";
  }
  else
    cout << p << "does not exist\n";

  return 0;
}

(code taken from boost filesystem tutorial)

and yet the console says:

terminate called after throwing an instance of 'std::bad_alloc'
  what(): std::bad_alloc
Aborted (core dumped)
  • 2
    Make sure you're not setting [`_SECURE_SCL_=0`](https://stackoverflow.com/a/12192167/7571171) or linking non-debug libraries to your debug project. This might solve the issue. Also, does it occur in debug builds only or in release builds as well? – Thomas Flinkow Feb 28 '18 at 07:22
  • [Cannot reproduce this](https://wandbox.org/permlink/PPnWvVDCbFMENtBq), what compiler and boost version are you using? – n. m. could be an AI Feb 28 '18 at 07:28
  • Use debugger and break on throw to see where it is coming from. – michalsrb Feb 28 '18 at 11:05

0 Answers0