Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: tidied up 1st NCCE/CS

...

Code Block
bgColor#FFcccc
langcpp
#include <cstdlib>

struct S {
  S();
  
  void f();
};

void fg() {
  S *s = static_cast<S *>(std::malloc(sizeof(S)));
 
  s->f();
 
  std::free(s);
}

...

Code Block
bgColor#ccccff
langcpp
#include <cstdlib>
#include <new>

struct S {
  S();
  
  void f();
};

void fg() {
  void *ptr = std::malloc(sizeof(S));
  S *s = new (ptr) S;

  s->f();
 
  s->~S();
  std::free(sptr);
}

Noncompliant Code Example

...