This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
I am wondering: could you add some testcases with failing conversion to the constructor type. I see four cases I'd like covered: a too long string, like that:I fail to see why this should fail. I think this is perfectly valid and equivalent to ['I', 'm']; the point of the constructor is too allow items which have different lengths. If they had all the same length, there were no need for the typespec (in this case).
write *, [ character(len=1) :: "I am too long", "me too" ]
and a value that doesn't fit in the constructor type, like that:I think one could add a range check here; with -fno-range-check it should compile (and give with -Wconversion a warning), but with -frange-check (= default) a overflow error should be printed.
write *, [ integer(4) :: huge(0_8) ]
Also, I think we should also include a testcase with derived types:Agreed.
And constructors withing constructors, like this:I think this fails currently - at least for strings, possibly also with -fbounds-check and other types; cf. PR35846. I think one problem are global variables. Note the test case in the PR is without typespecs.
print *, [ integer(kind=8) :: 4, [ integer(kind=4) :: 42, 12 ] ]
print *, [ character(len=8) :: "foo", [ character(len=4) :: "bar", "gee" ] ]
I believe this program is valid and thus there should not be any run-time error. This is similarly to:static void gfc_trans_array_ctor_element (stmtblock_t * pblock, tree desc, @@ -999,7 +1000,7 @@ - if (flag_bounds_check) + if (flag_bounds_check && !typespec_ctor)
I've tried to trigger that code and could not see it work. I cannot see a runtime error, neither with
call test ("this is long")
contains
subroutine test(s)
character(len=*) :: s
print *, [ character(len=3) :: s, "foo" ]
character(len=5) :: a a = 'foo' a = 'foobar'
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |