Bug 40196 - [F03] [F08] Type parameter inquiry (str%len, a%kind) and Complex parts (z%re, z%im)
Summary: [F03] [F08] Type parameter inquiry (str%len, a%kind) and Complex parts (z%re,...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: rejects-valid
: 81707 82709 (view as bug list)
Depends on:
Blocks: F2003 F2008 29962
  Show dependency treegraph
Reported: 2009-05-19 11:26 UTC by Tobias Burnus
Modified: 2018-03-04 12:44 UTC (History)
12 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2009-05-21 20:53:39


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-05-19 11:26:48 UTC
Type parameter inquiry:

str%len   is equivalent to   len(str)
  a%kind  is equivalent to   kind(a)

The real fun part starts with user-defined kinds, e.g.

type tp(dim)
  integer, KIND :: dim
  real :: dist(dim)
end type tp
type(tp) :: t(5)

print *, t%dist%dim

Quote from F2008 but F2003 should be the same:

"A type parameter inquiry is used to inquire about a type parameter of a data object. It applies to both intrinsic and derived types.

R616  type-param-inquiry   is   designator % type-param-name

C622 (R616) The type-param-name shall be the name of a type parameter of the declared type of the object designated by the designator.

A deferred type parameter of a pointer that is not associated or of an unallocated allocatable variable shall not be inquired about."
Comment 1 Tobias Burnus 2009-05-19 11:36:30 UTC
Another related item are complex parts; contrary to the type parameter inquiry above, those are lvalues and can be assigned to. (Again a F2003 feature, quote is however from F2008.)

"R615  complex-part-designator  is  designator % RE
                                or  designator % IM

 C621 (R615) The designator shall be of complex type.

 If complex-part-designator is designator%RE it designates the real part of
 designator. If it is designator%IM it designates the imaginary part of
 designator. The type of a complex-part-designator is real, and its kind and
 shape are those of the designator.

 NOTE 6.6
  The following are examples of complex part designators:

   impedance%re !-- Same value as REAL(impedance)
   fft%im       !-- Same value as AIMAG(fft)
   x%im = 0.0   !-- Sets the imaginary part of X to zero"
Comment 2 Daniel Franke 2009-12-06 16:59:27 UTC
Type parameter inquiries are also mentioned in PR29962, comment #10.
Comment 3 Sean Santos 2013-10-31 16:20:17 UTC
Real/imaginary parts seem to be Fortran 2008 only. Len/kind are still Fortran 2003.
Comment 4 janus 2017-08-27 09:59:12 UTC
*** Bug 81707 has been marked as a duplicate of this bug. ***
Comment 5 Jerry DeLisle 2017-10-01 18:26:19 UTC
I think originally this was an enhancement becasue we were focused on F95 back in 2009, now we are going for 2015 stuff so this one is higher interest. Taking.
Comment 6 Jerry DeLisle 2017-10-02 02:07:31 UTC
This works:

type tp(dim)
  integer, KIND :: dim = 3
  real :: dist(dim)
end type tp
type(tp) :: t(5)

print *, t%dist(2)
print *, t

Comment 7 Dominique d'Humieres 2017-10-24 23:51:56 UTC
*** Bug 82709 has been marked as a duplicate of this bug. ***
Comment 8 Jerry DeLisle 2017-12-31 16:29:01 UTC
I dont think I will have time for this one.