diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/special')
-rw-r--r-- | gcc/testsuite/g++.dg/special/conpr-1.C | 20 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/conpr-2.C | 23 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/conpr-2a.cc | 12 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/conpr-3.C | 23 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/conpr-3a.cc | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/conpr-3b.cc | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/conpr-4.C | 23 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/ecos.exp | 35 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/initp1.C | 90 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/initpri1.C | 62 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/special/initpri2.C | 39 |
11 files changed, 349 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/special/conpr-1.C b/gcc/testsuite/g++.dg/special/conpr-1.C new file mode 100644 index 000000000..ef694dbe6 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/conpr-1.C @@ -0,0 +1,20 @@ +/* { dg-do run { target init_priority } } */ + +#include <stdlib.h> + +class foo_t { + int x; +public: + foo_t(void) { x=1; } + int get(void) { return x; } +}; + +static foo_t foo __attribute__((init_priority(5000))); + +int main(void) { + + if (foo.get()) + exit(0); + else + abort(); +} diff --git a/gcc/testsuite/g++.dg/special/conpr-2.C b/gcc/testsuite/g++.dg/special/conpr-2.C new file mode 100644 index 000000000..ac826942a --- /dev/null +++ b/gcc/testsuite/g++.dg/special/conpr-2.C @@ -0,0 +1,23 @@ +/* { dg-do run { target init_priority } } */ +/* { dg-additional-sources "conpr-2a.cc" } */ + +#include <stdlib.h> + +class foo_t { + int x; + static int count; +public: + foo_t(void) { x=++count; } + int get(void) { return x; } +}; + +int foo_t::count; + +extern foo_t foo1, foo2; + +int main(void) { + + if ( (foo1.get() != 2) || (foo2.get() != 1) ) + abort(); + exit(0); +} diff --git a/gcc/testsuite/g++.dg/special/conpr-2a.cc b/gcc/testsuite/g++.dg/special/conpr-2a.cc new file mode 100644 index 000000000..69fb7d648 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/conpr-2a.cc @@ -0,0 +1,12 @@ +/* { dg-do run } */ + +class foo_t { + int x; + static int count; +public: + foo_t(void) { x=++count; } + int get(void) { return x; } +}; + +foo_t foo1 __attribute__((init_priority(6000))); +foo_t foo2 __attribute__((init_priority(5000))); diff --git a/gcc/testsuite/g++.dg/special/conpr-3.C b/gcc/testsuite/g++.dg/special/conpr-3.C new file mode 100644 index 000000000..71fadcc64 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/conpr-3.C @@ -0,0 +1,23 @@ +/* { dg-do run { target init_priority } } */ +/* { dg-additional-sources "conpr-3a.cc conpr-3b.cc" } */ + +#include <stdlib.h> + +class foo_t { + int x; + static int count; +public: + foo_t(void) { x=++count; } + int get(void) { return x; } +}; + +int foo_t::count; + +extern foo_t foo1, foo2; + +int main(void) { + + if ( (foo1.get() != 2) || (foo2.get() != 1) ) + abort(); + exit(0); +} diff --git a/gcc/testsuite/g++.dg/special/conpr-3a.cc b/gcc/testsuite/g++.dg/special/conpr-3a.cc new file mode 100644 index 000000000..b237bb57f --- /dev/null +++ b/gcc/testsuite/g++.dg/special/conpr-3a.cc @@ -0,0 +1,11 @@ +/* { dg-do run } */ + +class foo_t { + int x; + static int count; +public: + foo_t(void) { x=++count; } + int get(void) { return x; } +}; + +foo_t foo1 __attribute__((init_priority(6000))); diff --git a/gcc/testsuite/g++.dg/special/conpr-3b.cc b/gcc/testsuite/g++.dg/special/conpr-3b.cc new file mode 100644 index 000000000..b5efa0c35 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/conpr-3b.cc @@ -0,0 +1,11 @@ +/* { dg-do run } */ + +class foo_t { + int x; + static int count; +public: + foo_t(void) { x=++count; } + int get(void) { return x; } +}; + +foo_t foo2 __attribute__((init_priority(5000))); diff --git a/gcc/testsuite/g++.dg/special/conpr-4.C b/gcc/testsuite/g++.dg/special/conpr-4.C new file mode 100644 index 000000000..40ce21d98 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/conpr-4.C @@ -0,0 +1,23 @@ +/* { dg-do run { target init_priority } } */ +/* { dg-additional-sources "conpr-3b.cc conpr-3a.cc" } */ + +#include <stdlib.h> + +class foo_t { + int x; + static int count; +public: + foo_t(void) { x=++count; } + int get(void) { return x; } +}; + +int foo_t::count; + +extern foo_t foo1, foo2; + +int main(void) { + + if ( (foo1.get() != 2) || (foo2.get() != 1) ) + abort(); + exit(0); +} diff --git a/gcc/testsuite/g++.dg/special/ecos.exp b/gcc/testsuite/g++.dg/special/ecos.exp new file mode 100644 index 000000000..eb0c1eacd --- /dev/null +++ b/gcc/testsuite/g++.dg/special/ecos.exp @@ -0,0 +1,35 @@ +# Copyright (C) 1999, 2001, 2003, 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# Please email any bugs, comments, and/or additions to this file to: +# jlarmour@cygnus.co.uk + +# This file was written by Jonathan Larmour (jlarmour@cygnus.co.uk). + +# G++ testsuite that uses the `dg.exp' driver. + +# Load support procs. +load_lib g++-dg.exp + +# Initialize 'dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.C]] "" "" + +# All done. +dg-finish + diff --git a/gcc/testsuite/g++.dg/special/initp1.C b/gcc/testsuite/g++.dg/special/initp1.C new file mode 100644 index 000000000..4a539a5a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/initp1.C @@ -0,0 +1,90 @@ +/* { dg-do run { target init_priority } } */ +#include <stdlib.h> + +class Two { +private: + int i, j, k; +public: + static int count; + Two( int ii, int jj ) { i = ii; j = jj; k = count++; }; + Two( void ) { i = 0; j = 0; k = count++; }; + int eye( void ) { return i; }; + int jay( void ) { return j; }; + int kay( void ) { return k; }; +}; + +extern Two foo; +extern Two goo; +extern Two coo[]; +extern Two koo[]; + +Two foo __attribute__((init_priority(1005))) ( 5, 6 ); + +Two goo __attribute__((init_priority(1007))) = Two( 7, 8 ); + +Two doo[ 3 ]; + +Two hoo[ 3 ] = { + Two( 11, 12 ), + Two( 13, 14 ), + Two( 15, 16 ) +}; + +Two coo[ 3 ] __attribute__((init_priority(1000))); + +Two koo[ 3 ] __attribute__((init_priority(1000))) = { + Two( 21, 22 ), + Two( 23, 24 ), + Two( 25, 26 ) +}; + +Two xoo[ 3 ] __attribute__((init_priority(1100))); + +Two zoo[ 3 ] __attribute__((init_priority(1100))) = { + Two( 31, 32 ), + Two( 33, 34 ), + Two( 35, 36 ) +}; + +int Two::count; + +long x = 0; + +#define X( n ) \ + do { if ( x & (1L << (n)) ) return 1; else x |= (1L << (n)); } while (0) + +int main() +{ + + X( coo[0].kay() ); + X( coo[1].kay() ); + X( coo[2].kay() ); + X( koo[0].kay() ); + X( koo[1].kay() ); + X( koo[2].kay() ); + if ( 0x3f != x ) abort (); + + X( foo.kay() ); + if ( 0x7f != x ) abort (); + + X( goo.kay() ); + if ( 0xff != x ) abort (); + + X( xoo[0].kay() ); + X( xoo[1].kay() ); + X( xoo[2].kay() ); + X( zoo[0].kay() ); + X( zoo[1].kay() ); + X( zoo[2].kay() ); + if ( 0x3fff != x ) abort (); + + X( doo[0].kay() ); + X( doo[1].kay() ); + X( doo[2].kay() ); + X( hoo[0].kay() ); + X( hoo[1].kay() ); + X( hoo[2].kay() ); + if ( 0xfffff != x ) abort (); + + exit (0); +} diff --git a/gcc/testsuite/g++.dg/special/initpri1.C b/gcc/testsuite/g++.dg/special/initpri1.C new file mode 100644 index 000000000..bd24961e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/initpri1.C @@ -0,0 +1,62 @@ +/* { dg-do run { target init_priority } } */ + +extern "C" void abort (); + +int i; +int j; + +void c1() __attribute__((constructor (500))); +void c2() __attribute__((constructor (700))); +void c3() __attribute__((constructor (600))); + +void c1() { + if (i++ != 0) + abort (); +} + +void c2() { + if (i++ != 2) + abort (); +} + +void c3() { + if (i++ != 1) + abort (); +} + +void d1() __attribute__((destructor (500))); +void d2() __attribute__((destructor (700))); +void d3() __attribute__((destructor (600))); + +void d1() { + if (--i != 0) + abort (); +} + +void d2() { + if (--i != 2) + abort (); +} + +void d3() { + if (j != 2) + abort (); + if (--i != 1) + abort (); +} + +void cd4() __attribute__((constructor (800), destructor (800))); + +void cd4() { + if (i != 3) + abort (); + ++j; +} + +int main () { + if (i != 3) + return 1; + if (j != 1) + abort (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/special/initpri2.C b/gcc/testsuite/g++.dg/special/initpri2.C new file mode 100644 index 000000000..fa9fda0d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/special/initpri2.C @@ -0,0 +1,39 @@ +/* { dg-do compile { target init_priority } } */ + +/* Priorities must be in the range [0, 65535]. */ +void c1() + __attribute__((constructor (-1))); /* { dg-error "priorities" } */ +void c2() + __attribute__((constructor (65536))); /* { dg-error "priorities" } */ +void d1() + __attribute__((destructor (-1))); /* { dg-error "priorities" } */ +void d2() + __attribute__((destructor (65536))); /* { dg-error "priorities" } */ + +/* Priorities 0-100 are reserved for system libraries. */ +void c3() + __attribute__((constructor (50))); /* { dg-warning "reserved" } */ +void d3() + __attribute__((constructor (50))); /* { dg-warning "reserved" } */ + +/* Priorities must be integral constants. */ + +/* Pointers, even with constant values, are not allowed. */ +void c4() + __attribute__((constructor ((void*) 500))); /* { dg-error "priorities" } */ +void d4() + __attribute__((destructor ((void*) 500))); /* { dg-error "priorities" } */ + +/* Integer variables are not allowed. */ +int i; +void c5() + __attribute__((constructor ((i)))); /* { dg-error "priorities" } */ +void d5() + __attribute__((destructor ((i)))); /* { dg-error "priorities" } */ + +/* Enumeration constants are allowed. */ +enum E { e = 500 }; +void c6() + __attribute__((constructor ((e)))); +void d6() + __attribute__((destructor ((e)))); |