// Prevents the use of the new operator by forcing a linker error if it is used.
// Simply include this in your application and the linker will tell you if you
// use new somewhere (even in third party code linked to your application).

#ifndef PLS_PROHIBIT_NEW_H
#define PLS_PROHIBIT_NEW_H

#include <iostream>

// Comment this out and set a debug point in the std::cout
// line to find out where the new is located in case you
// get an linker error.
#define NEW_LINK_ERROR

#ifdef NEW_LINK_ERROR
// This will cause a linker error if new is used in the code.
// We also exit if it is somehow still called.
inline void *operator new(std::size_t) {
  extern int bare_new_erroneously_called();
  exit(bare_new_erroneously_called() | 1);
}
#else
// Use this + debugging point to find out where we use a new
inline void * operator new (std::size_t) {
//    extern int bare_new_erroneously_called();
    std::cout << "New called! Exiting application, no dynamic memory allocation allowed!";
    exit(1);
}
#endif

#endif //PLS_PROHIBIT_NEW_H
