| 1 |
// { dg-do run } |
| 2 |
// Copyright (C) 1999 Free Software Foundation, Inc. |
| 3 |
// Contributed by Nathan Sidwell 21 Nov 1999 <[email protected]> |
| 4 |
|
| 5 |
// make sure __FUNCTION__ and __PRETTY_FUNCTION__ work in templates |
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
#include <string.h> |
| 9 |
|
| 10 |
static bool bad = false; |
| 11 |
|
| 12 |
template<class T> void f1 (T) |
| 13 |
{ |
| 14 |
char const *function = __FUNCTION__; |
| 15 |
char const *pretty = __PRETTY_FUNCTION__; |
| 16 |
|
| 17 |
printf ("generic\n"); |
| 18 |
printf ("__FUNCTION__ %s\n", function); |
| 19 |
printf ("__PRETTY_FUNCTION__ %s\n", pretty); |
| 20 |
|
| 21 |
if (strcmp (function, "f1")) |
| 22 |
bad = true; |
| 23 |
if (strcmp (pretty, "void f1(T) [with T = float]")) // only for float instantiation |
| 24 |
bad = true; |
| 25 |
} |
| 26 |
|
| 27 |
template<> void f1<int> (int) |
| 28 |
{ |
| 29 |
char const *function = __FUNCTION__; |
| 30 |
char const *pretty = __PRETTY_FUNCTION__; |
| 31 |
|
| 32 |
printf ("specialized\n"); |
| 33 |
printf ("__FUNCTION__ %s\n", function); |
| 34 |
printf ("__PRETTY_FUNCTION__ %s\n", pretty); |
| 35 |
|
| 36 |
if (strcmp (function, "f1<int>")) |
| 37 |
bad = true; |
| 38 |
if (strcmp (pretty, "void f1(T) [with T = int]")) |
| 39 |
bad = true; |
| 40 |
} |
| 41 |
|
| 42 |
int main () |
| 43 |
{ |
| 44 |
f1(0); // f1<int> |
| 45 |
f1(0.0f); // f1<float> |
| 46 |
return bad; |
| 47 |
} |