News for hackers. Stuff that matters.
Re:Why undefined behavior may call a never-called function by beatbrokedown on Sunday September 24, 2017 @11:37AM (#15325078)
If you make one small change to this file you can cause clang and gcc to both prevent this from compiling if you are using warnings.

  namespace {
    void NeverCalled() { Do = EraseAll; }
  }
or marking NeverCalled as static itself.

Results in warning: unused function NeverCalled.

In general this is best practice for functions defined and used in a single translation unit.

Re:Why undefined behavior may call a never-called function by saalweachter on Sunday September 24, 2017 @12:16PM (#15325273)
That's a vital part of the setup.

You could hypothetically link this compilation unit against another unit which included:

  void NeverCalled();
  struct A {
    A() { NeverCalled(); }
  };
  A a;
Re:Why undefined behavior may call a never-called function by eridius on Sunday September 24, 2017 @03:25PM (#15326078)
You don't even need C++, you can just use C and __attribute__((constructor)).
Re:Why undefined behavior may call a never-called function by pjmlp on Monday September 25, 2017 @02:25AM (#15328440)
Which is a GCC specific extension and not ANSI C.