Bug 20323 - optional arguments incorrectly accepted in specification expressions
Summary: optional arguments incorrectly accepted in specification expressions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, patch
Depends on:
Blocks:
 
Reported: 2005-03-04 19:56 UTC by Toby White
Modified: 2005-03-13 18:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-03-12 23:37:20


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Toby White 2005-03-04 19:56:57 UTC
In the program below, the optional argument arg is used as part of the 
specification expression for the length of a string. This is forbidden by 
section 7.1.6.2; constraint (2) of the F95 standard (and wouldn't make 
much sense anyway - what happens when the function is called without the 
optional argument?) 
 
gfortran accepts it without complaint, though. 
 
parabrisas:~/test% cat testpresent.f90  
function testpresent(arg) 
   integer, intent(in), optional :: arg 
   character(len=arg) :: s 
   logical :: testpresent 
 
   testpresent=.true. 
 
end function testpresent 
parabrisas:~/test% gfortran -c testpresent.f90  
parabrisas:~/test% gfortran -v 
Using built-in specs. 
Configured with: ../gcc/configure --prefix=/home/tow/root/gcc-4.0 
--enable-languages=c,f95 : (reconfigured) ../gcc/configure 
--prefix=/home/tow/root/gcc-4.0 
--with-gcc-version-trigger=/home/tow/dl/gcc/gcc/gcc/version.c 
--enable-languages=c,f95 --no-create --no-recursion : 
(reconfigured) ../gcc/configure --prefix=/home/tow/root/gcc-4.0 
--with-gcc-version-trigger=/home/tow/dl/gcc/gcc/gcc/version.c 
--enable-languages=c,f95 --no-create --no-recursion 
Thread model: posix 
gcc version 4.0.0 20050127 (experimental)
Comment 1 Thomas Koenig 2005-03-09 16:01:50 UTC
The complaint is a segfault at runtime when
you actually want to do anything with the
string whose length depends on a missing
optional argument.  This isn't too bad (the
same thing happens if you access a missing
optional argument).

Thomas
Comment 2 Toby White 2005-03-09 16:11:42 UTC
 (In reply to comment #1) 
> The complaint is a segfault at runtime when 
> you actually want to do anything with the 
> string whose length depends on a missing 
> optional argument.  This isn't too bad (the 
> same thing happens if you access a missing 
> optional argument). 
 
Indeed - but even if the optional argument were present, you're still not 
allowed to access it in a specification expression, and this is a constraint 
that the compiler is required to detect at compile time. (It's a constraint 
that I'd quite like to see partially lifted - it would be very useful to be 
able to use present(arg) as part of a specification expression -  but it is 
forbidden according to the current standard.) 
 
Comment 3 Tobias Schlüter 2005-03-13 17:23:12 UTC
Patch here: http://gcc.gnu.org/ml/fortran/2005-03/msg00220.html
Comment 4 GCC Commits 2005-03-13 18:37:25 UTC
Subject: Bug 20323

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tobi@gcc.gnu.org	2005-03-13 18:37:17

Modified files:
	gcc/fortran    : ChangeLog resolve.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: spec_expr_1.f90 

Log message:
	fortran/
	PR fortran/20323
	* resolve.c (gfc_resolve): Check if character lengths are
	specification expressions.
	
	testsuite/
	PR fortran/20323
	* gfortran.dg/spec_expr_1.f90: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&r1=1.349&r2=1.350
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/resolve.c.diff?cvsroot=gcc&r1=1.35&r2=1.36
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5154&r2=1.5155
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/spec_expr_1.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 GCC Commits 2005-03-13 18:40:34 UTC
Subject: Bug 20323

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tobi@gcc.gnu.org	2005-03-13 18:40:29

Modified files:
	gcc/fortran    : ChangeLog resolve.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gfortran.dg: spec_expr_1.f90 

Log message:
	fortran/
	> PR fortran/20323
	> * resolve.c (gfc_resolve): Check if character lengths are
	> specification expressions.
	>
	> testsuite/
	> PR fortran/20323
	> * gfortran.dg/spec_expr_1.f90: New test.
	>

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.335.2.10&r2=1.335.2.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fortran/resolve.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.34.2.1&r2=1.34.2.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.38&r2=1.5084.2.39
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/spec_expr_1.f90.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 6 Tobias Schlüter 2005-03-13 18:42:22 UTC
Fixed.