1 // PR c++/6794 2 // Test whether __PRETTY_FUNCTION__ works in templates, functions and 3 // in initializers at global scope 4 // { dg-do run } 5 // { dg-options "" } 6 7 extern "C" void __assert_fail (const char *, const char *, 8 unsigned int, const char *) 9 throw() __attribute__((noreturn)); 10 extern "C" void abort (void); 11 extern "C" void exit (int); 12 13 #define str(expr) #expr 14 #define assert(expr) \ 15 ((expr) ? 0 : (__assert_fail (str(expr), __FILE__, __LINE__, \ 16 __PRETTY_FUNCTION__), 0)) 17 18 int __attribute__((noinline)) 19 foo (void) 20 { 21 return 1; 22 } 23 24 template<class T> int 25 bar (T) 26 { 27 return (assert (foo ()), 1); 28 } 29 30 template<> int 31 bar<int> (int) 32 { 33 return (assert (foo ()), 2); 34 } 35 36 int a = (assert (foo ()), 1); 37 int b = (assert (foo ()), 2); 38 39 int 40 main () 41 { 42 double c = 1.0; 43 unsigned char *d = 0; 44 int e = (assert (foo ()), 3); 45 46 bar (c); 47 bar (d); 48 bar (e); 49 } 50 51 namespace N 52 { 53 int f = (assert (foo ()), 4); 54 } 55 56 void __attribute__((noinline)) 57 __assert_fail (const char *cond, const char *file, unsigned int line, 58 const char *pretty) throw () 59 { 60 abort (); 61 } 62