summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/builtin-redefine.c
blob: 1d0f29da8dac4043c661045c7f1bbf92afae1d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Test -Wno-builtin-macro-redefined warnings.  */

/* { dg-do compile } */
/* { dg-options "-Wno-builtin-macro-redefined -U__DATE__ -D__TIME__=X" } */

/* Check date, time, and datestamp built-ins warnings may be suppressed.  */

#if defined(__DATE__)
#error "__DATE__ is defined, but should not be (-U command line error)"
/* { dg-bogus "__DATE__ is defined" "" { target *-*-* } 9 } */
#endif

#if __TIME__ != X
#error "__TIME__ is not defined as expected (-D command line error)"
/* { dg-bogus "__TIME__ is not defined" "" { target *-*-* } 14 } */
#endif

#if !defined(__TIMESTAMP__)
#error "__TIMESTAMP__ is not defined (built-in macro expectation error)"
/* { dg-bogus "__TIMESTAMP__ is not defined" "" { target *-*-* } 19 } */
#endif


#undef __TIME__              /* Undefine while defined.  */
#undef __TIME__              /* Undefine while already undefined.  */

#define __TIME__ "X"         /* Define while undefined.  */
#define __TIME__ "X"         /* Re-define while defined.  */

#define __TIME__ "Y"         /* { dg-warning "\"__TIME__\" redefined" } */
/* { dg-message "previous definition" "" { target *-*-* } 28 } */

#undef __TIME__              /* Undefine while defined.  */


#undef __DATE__              /* Undefine while already undefined.  */

#define __DATE__ "X"         /* Define while undefined.  */
#define __DATE__ "X"         /* Re-define while defined.  */

#define __DATE__ "Y"         /* { dg-warning "\"__DATE__\" redefined" } */
/* { dg-message "previous definition" "" { target *-*-* } 39 } */

#undef __DATE__              /* Undefine while defined.  */


#define __TIMESTAMP__ "X"    /* Define while already defined.  */
#define __TIMESTAMP__ "X"    /* Re-define while defined.  */

#define __TIMESTAMP__ "Y"    /* { dg-warning "\"__TIMESTAMP__\" redefined" } */
/* { dg-message "previous definition" "" { target *-*-* } 48 } */

#undef __TIMESTAMP__         /* Undefine while defined.  */


/* Check other built-ins with warnings that may be suppressed.  */

#if !defined(__FILE__) || !defined(__BASE_FILE__)
#error "Expected built-in is not defined (built-in macro expectation error)"
/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } 59 } */
#endif

#define __FILE__ "X"         /* Define while already defined.  */
#define __BASE_FILE__ "X"    /* Define while already defined.  */


/* Check selected built-ins not affected by warning suppression. */

#if !defined(__LINE__) || !defined(__INCLUDE_LEVEL__) || !defined(__COUNTER__)
#error "Expected built-in is not defined (built-in macro expectation error)"
/* { dg-bogus "Expected built-in is not defined" "" { target *-*-* } 70 } */
#endif

#define __LINE__ 0           /* { dg-warning "\"__LINE__\" redef" } */
#define __INCLUDE_LEVEL__ 0  /* { dg-warning "\"__INCLUDE_LEVEL__\" redef" } */
#define __COUNTER__ 0        /* { dg-warning "\"__COUNTER__\" redef" } */


int unused;  /* Silence `ISO C forbids an empty translation unit' warning.  */