fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using std::cout;
  5. using std::endl;
  6.  
  7. #define PFN(x) cout << x << __PRETTY_FUNCTION__ << endl
  8. #define PF PFN("")
  9. #define NL cout << endl
  10.  
  11. struct A {
  12. constexpr A() { PF; }
  13. virtual ~A() { PF; NL; }
  14. };
  15.  
  16. struct B : A {
  17. constexpr B() { PFN(" "); }
  18. virtual ~B() { PFN(" "); }
  19. };
  20.  
  21. int main(int argc, char** argv) {
  22. { A a; }
  23. { B b; }
  24. A* a = new B;
  25. delete a;
  26. return 0;
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:12:15: error: constexpr constructor never produces a constant expression [-Winvalid-constexpr]
    constexpr A() { PF; }
              ^
prog.cpp:12:21: note: non-constexpr function 'operator<<<std::char_traits<char> >' cannot be used in a constant expression
    constexpr A() { PF; }
                    ^
prog.cpp:8:16: note: expanded from macro 'PF'
#define PF     PFN("")
               ^
prog.cpp:7:26: note: expanded from macro 'PFN'
#define PFN(x) cout << x << __PRETTY_FUNCTION__ << endl
                         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/ostream:556:5: note: declared here
    operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
    ^
1 error generated.
stdout
Standard output is empty