summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/structure_constructor_1.f03
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gfortran.dg/structure_constructor_1.f03
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gfortran.dg/structure_constructor_1.f03')
-rw-r--r--gcc/testsuite/gfortran.dg/structure_constructor_1.f0374
1 files changed, 74 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/structure_constructor_1.f03 b/gcc/testsuite/gfortran.dg/structure_constructor_1.f03
new file mode 100644
index 000000000..8f8f58ef9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/structure_constructor_1.f03
@@ -0,0 +1,74 @@
+! { dg-do run }
+! Simple structure constructors, without naming arguments, default values
+! or inheritance and the like.
+
+PROGRAM test
+ IMPLICIT NONE
+
+ ! Empty structuer
+ TYPE :: empty_t
+ END TYPE empty_t
+
+ ! Structure of basic data types
+ TYPE :: basics_t
+ INTEGER :: i
+ REAL :: r
+ COMPLEX :: c
+ LOGICAL :: l
+ END TYPE basics_t
+
+ ! Structure with strings
+ TYPE :: strings_t
+ CHARACTER(len=5) :: str1, str2
+ CHARACTER(len=10) :: long
+ END TYPE strings_t
+
+ ! Structure with arrays
+ TYPE :: array_t
+ INTEGER :: ints(2:5)
+ REAL :: matrix(2, 2)
+ END TYPE array_t
+
+ ! Structure containing structures
+ TYPE :: nestedStruct_t
+ TYPE(basics_t) :: basics
+ TYPE(array_t) :: arrays
+ END TYPE nestedStruct_t
+
+ TYPE(empty_t) :: empty
+ TYPE(basics_t) :: basics
+ TYPE(strings_t) :: strings
+ TYPE(array_t) :: arrays
+ TYPE(nestedStruct_t) :: nestedStruct
+
+ empty = empty_t ()
+
+ basics = basics_t (42, -1.5, (.5, .5), .FALSE.)
+ IF (basics%i /= 42 .OR. basics%r /= -1.5 &
+ .OR. basics%c /= (.5, .5) .OR. basics%l) THEN
+ CALL abort()
+ END IF
+
+ strings = strings_t ("hello", "abc", "this one is long")
+ IF (strings%str1 /= "hello" .OR. strings%str2 /= "abc" &
+ .OR. strings%long /= "this one i") THEN
+ CALL abort()
+ END IF
+
+ arrays = array_t ( (/ 1, 2, 3, 4 /), RESHAPE((/ 5, 6, 7, 8 /), (/ 2, 2 /)) )
+ IF (arrays%ints(2) /= 1 .OR. arrays%ints(3) /= 2 &
+ .OR. arrays%ints(4) /= 3 .OR. arrays%ints(5) /= 4 &
+ .OR. arrays%matrix(1, 1) /= 5. .OR. arrays%matrix(2, 1) /= 6. &
+ .OR. arrays%matrix(1, 2) /= 7. .OR. arrays%matrix(2, 2) /= 8.) THEN
+ CALL abort()
+ END IF
+
+ nestedStruct = nestedStruct_t (basics_t (42, -1.5, (.5, .5), .FALSE.), arrays)
+ IF (nestedStruct%basics%i /= 42 .OR. nestedStruct%basics%r /= -1.5 &
+ .OR. nestedStruct%basics%c /= (.5, .5) .OR. nestedStruct%basics%l &
+ .OR. ANY(nestedStruct%arrays%ints /= arrays%ints) &
+ .OR. ANY(nestedStruct%arrays%matrix /= arrays%matrix)) THEN
+ CALL abort()
+ END IF
+
+END PROGRAM test