Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Overloading structure constructors

normcler
Beginner
433 Views
Hello everyone,

Please look at the following program:

[fortran]module My_complex_mod implicit none private public :: my_complex_t type, public :: my_complex_t real :: argument = 0.0, modulus = 0.0 end type my_complex_t interface my_complex_t module procedure Complex_to_my_complex module procedure Two_reals_to_my_complex end interface contains function Complex_to_my_complex (complex_) result (return_my_complex) complex, intent (in) :: complex_ type (my_complex_t) :: return_my_complex real :: aimaginary_part, real_part aimaginary_part = aimag (complex_) real_part = real (complex_) return_my_complex % argument = atan2 (aimaginary_part, real_part) return_my_complex % modulus = sqrt (aimaginary_part * aimaginary_part + real_part * real_part) end function Complex_to_my_complex function Two_reals_to_my_complex (x_, y_) result (return_my_complex) real, intent (in) :: x_ real, intent (in), optional :: y_ type (my_complex_t) :: return_my_complex complex (kind (x_) ) :: complex_num complex_num = cmplx (x_, y_) return_my_complex = Complex_to_my_complex (complex_num) end function two_reals_to_my_complex end module My_complex_mod program Complex_test use My_complex_mod, only : my_complex_t implicit none type (my_complex_t) :: a, b, c, d, e complex :: w w = cmplx (1.0, 1.0) a = my_complex_t (argument = 5.6, modulus = 1.0) b = my_complex_t (complex_=w) c = my_complex_t (x_=0.0, y_=1.0) d = my_complex_t (-1.0, -1.0) e = my_complex_t (w) end program Complex_test [/fortran]
Here is the result of compiling this with version 12.1.3 of the Intel compiler:

norm@oxford:~/fortran/code/StructOver$ ifort -c -v complex_testP.f90
ifort version 12.1.3
/opt/intel/composer_xe_2011_sp1.9.293/bin/intel64/fortcom -D__INTEL_COMPILER=1210 -D__unix__ -D__unix -D__linux__ -D__linux -D__gnu_linux__ -Dunix -Dlinux -D__ELF__ -D__x86_64 -D__x86_64__ -D_MT -D__INTEL_COMPILER_BUILD_DATE=20120212 -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__pentium4 -D__pentium4__ -D__tune_pentium4__ -D__SSE2__ -D__SSE__ -D__MMX__ -mGLOB_pack_sort_init_list -I. -I/opt/intel/composer_xe_2011_sp1.9.293/mkl/include -I/opt/intel/composer_xe_2011_sp1.9.293/compiler/include/intel64 -I/opt/intel/composer_xe_2011_sp1.9.293/compiler/include -I/usr/local/include -I/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include -I/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include-fixed -I/usr/include -O2 -simd -mP1OPT_version=12.1-intel64 -mGLOB_diag_file=complex_testP.diag -mGLOB_source_language=GLOB_SOURCE_LANGUAGE_F90 -mGLOB_tune_for_fort -mGLOB_use_fort_dope_vector -mP2OPT_static_promotion -mP1OPT_print_version=FALSE -mCG_use_gas_got_workaround=F -mP2OPT_align_option_used=TRUE -mGLOB_gcc_version=443 "-mGLOB_options_string=-c -v" -mGLOB_cxx_limited_range=FALSE -mCG_extend_parms=FALSE -mGLOB_as_output_backup_file_name=/tmp/ifortfEzCN1as_.s -mIPOPT_activate -mIPOPT_lite -mGLOB_machine_model=GLOB_MACHINE_MODEL_EFI2 -mGLOB_product_id_code=0x22006d8c -mCG_bnl_movbe=T -mGLOB_extended_instructions=0x8 -mP3OPT_use_mspp_call_convention -mP2OPT_subs_out_of_bound=FALSE -mGLOB_ansi_alias -mPGOPTI_value_profile_use=T -mP2OPT_il0_array_sections=TRUE -mP2OPT_hlo_level=2 -mP2OPT_hlo -mP2OPT_hpo_rtt_control=0 -mIPOPT_args_in_regs=0 -mP2OPT_disam_assume_nonstd_intent_in=FALSE -mGLOB_imf_mapping_library=/opt/intel/composer_xe_2011_sp1.9.293/bin/intel64/libiml_attr.so -mIPOPT_obj_output_file_name=complex_testP.o -mGLOB_linker_version=2.20.1-system.20100303 -mGLOB_long_size_64 -mGLOB_routine_pointer_size_64 -mP3OPT_asm_target=P3OPT_ASM_TARGET_GAS -mGLOB_async_unwind_tables=TRUE -mGLOB_obj_output_file=complex_testP.o -mGLOB_source_dialect=GLOB_SOURCE_DIALECT_FORTRAN -mP1OPT_source_file_name=complex_testP.f90 -mP2OPT_symtab_type_copy=true complex_testP.f90
complex_testP.f90(52): error #8213: A keyword in the structure constructor is not the name of a type component. [COMPLEX_]
b = my_complex_t (complex_=w)
--------------------^
complex_testP.f90(53): error #8213: A keyword in the structure constructor is not the name of a type component. [X_]
c = my_complex_t (x_=0.0, y_=1.0)
--------------------^
complex_testP.f90(53): error #8213: A keyword in the structure constructor is not the name of a type component. [Y_]
c = my_complex_t (x_=0.0, y_=1.0)
----------------------------^
compilation aborted for complex_testP.f90 (code 1)

Here's the result compiling the same code with version 5.3 of the NAG compiler:

norm@oxford:~/fortran/code/StructOver$ nagfor -c -v complex_testP.f90
NAG Fortran Compiler Release 5.3(866)
complex_testP.f90:
Questionable: complex_testP.f90, line 56: Variable A set but never referenced
Questionable: complex_testP.f90, line 56: Variable B set but never referenced
Questionable: complex_testP.f90, line 56: Variable C set but never referenced
Questionable: complex_testP.f90, line 56: Variable D set but never referenced
Questionable: complex_testP.f90, line 56: Variable E set but never referenced
[NAG Fortran Compiler normal termination, 5 warnings]

Which one is correct (ignoring the "Questionable" comments in NAG)?

Norm Clerman
0 Kudos
3 Replies
Steven_L_Intel1
Employee
433 Views
Hi, Norm...

I know we have some issues in this area. I am pretty sure NAG is correct here. I will forward this to the developers. Thanks for the example.
0 Kudos
normcler
Beginner
433 Views
Thanks, Steve,

Please also refer to my old premier support issue number 598088 on this one. I also think the Intel compiler errs here.

Norm
0 Kudos
Steven_L_Intel1
Employee
433 Views
Norm,

I'm a bit confused by what you show as I see something else entirely different.

With the source you show here, ifort complains that you've given my_complex_t the PUBLIC attribute twice, which is not allowed by the standard. If I take out the second specification of PUBLIC, the source compiles without errors in 12.1.3 (Update 9)

[plain][sblionel@f90srv32 ~/project]$ source intel/composerxe/bin/compilervars.csh intel64 [sblionel@f90srv32 ~/project]$ ifort -V -c complex_testP.f90 Intel Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.3.293 Build 20120212 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. Intel Fortran 12.1-2098 [sblionel@f90srv32 ~/project]$ [/plain] The program you have here is not the same source as in issue 598088. The source from issue 598088 does have similar diagnostics to what you report here, but not the same. I think I related to you earlier that the program submitted for that issue had an error.

Which source did you use in the compilation in your post here?
0 Kudos
Reply