Bug 46020 - Improve error string for BIND(C) diagnostic for len>1 character return type
Summary: Improve error string for BIND(C) diagnostic for len>1 character return type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Fortran_character ISO_C_Binding
  Show dependency treegraph
 
Reported: 2010-10-14 17:08 UTC by Tobias Burnus
Modified: 2018-11-02 20:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-03-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-10-14 17:08:24 UTC
The following is a misleading error message. The return type may be a character string -- but only of length one!


FUNCTION F_X(A) bind(c,name='F_X')
1
Error: Return type of BIND(C) function 'f_x' at (1) cannot be a character string

Example (taken from: http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/ee444a5894644f72#)

FUNCTION F_X(A) bind(c,name='F_X')
   CHARACTER*(*) F_X
END FUNCTION


NAG prints:
  Error: BIND(C) function F_X has assumed CHARACTER length
though the error for "CHARACTER(len=4)" is also not that helpful:
  Error: BIND(C) function F_X has CHARACTER(LEN=4)


Maybe one can keep the current string and only add "with length > 1", i.e.

Error: Return type of BIND(C) function 'f_x' at (1) cannot be a character string with length > 1
Comment 1 Tobias Burnus 2010-10-14 17:14:45 UTC
Thinking of it again, one probably needs also NAGs error message as:

FUNCTION F_X(A) bind(c,name='F_X')
   CHARACTER*(*) F_X
END FUNCTION

...

interface
  FUNCTION F_X(A) bind(c,name='F_X')
     CHARACTER*(1) F_X
  END FUNCTION
end interface

is also invalid - even though the effective string length is one;

F2008 has: "If the type is character, the length type parameter is interoperable if and only if its value is one." [...]

[only interoperable] "if it is of type character its length is not assumed or declared by an expression that is not a constant expression."

Thus, one could think of handling the assumed length case explicitly. Or one uses, e.g.

Error: Return type of BIND(C) function 'f_x' at (1) of character type must have
length 1
Comment 2 Alexandre Oliva 2010-11-26 04:25:37 UTC
Author: aoliva
Date: Fri Nov 26 04:25:32 2010
New Revision: 167160

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167160
Log:
PR other/46020
* configure.ac (CXX_FOR_TARGET): Add -funconfigured-libstdc++-v3.
* Makefile.def (CXX_FOR_TARGET): Removed from flags_to_pass.
* Makefile.tpl (CXX_FOR_TARGET_FLAG_TO_PASS): New.
(BASE_FLAGS_TO_PASS): Use it.
* configure: Rebuilt.
* Makefile.in: Rebuilt.

Modified:
    trunk/ChangeLog
    trunk/Makefile.def
    trunk/Makefile.in
    trunk/Makefile.tpl
    trunk/configure
    trunk/configure.ac
Comment 3 Alexandre Oliva 2010-11-26 04:29:45 UTC
Author: aoliva
Date: Fri Nov 26 04:29:41 2010
New Revision: 167163

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167163
Log:
PR other/46020
* configure.ac (CXX_FOR_TARGET): Add -funconfigured-libstdc++-v3.
* Makefile.def (CXX_FOR_TARGET): Removed from flags_to_pass.
* Makefile.tpl (CXX_FOR_TARGET_FLAG_TO_PASS): New.
(BASE_FLAGS_TO_PASS): Use it.
* configure: Rebuilt.
* Makefile.in: Rebuilt.

Modified:
    branches/transactional-memory/ChangeLog
    branches/transactional-memory/Makefile.def
    branches/transactional-memory/Makefile.in
    branches/transactional-memory/Makefile.tpl
    branches/transactional-memory/configure
    branches/transactional-memory/configure.ac
Comment 4 Alexandre Oliva 2010-12-06 12:55:15 UTC
Sorry about the spam, these check ins were meant for bug 46026.
Comment 5 Alexandre Oliva 2010-12-06 13:04:11 UTC
Author: aoliva
Date: Mon Dec  6 13:04:07 2010
New Revision: 167491

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167491
Log:
Check in for PR other/46020 was meant for PR other/46026.

Modified:
    branches/transactional-memory/ChangeLog
Comment 6 Alexandre Oliva 2010-12-06 13:11:55 UTC
Author: aoliva
Date: Mon Dec  6 13:11:51 2010
New Revision: 167493

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167493
Log:
Check in for PR other/46020 was meant for PR other/46026.

Modified:
    trunk/ChangeLog
Comment 7 Tobias Burnus 2010-12-06 13:40:31 UTC
Status: Unfixed. See comment 0 for the description.
Comment 8 Dominique d'Humieres 2014-03-22 19:43:29 UTC
Related to pr46496.
Comment 9 Thomas Koenig 2018-11-01 11:56:14 UTC
Author: tkoenig
Date: Thu Nov  1 11:55:43 2018
New Revision: 265716

URL: https://gcc.gnu.org/viewcvs?rev=265716&root=gcc&view=rev
Log:
2018-11-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46020
    * gfortran.dg/bind_c_usage_7.f90: Adjust error message.
    * gfortran.dg/bind_c_usage_32.f90: New test.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/bind_c_usage_7.f03
Comment 10 Thomas Koenig 2018-11-01 11:56:58 UTC
Author: tkoenig
Date: Thu Nov  1 11:56:26 2018
New Revision: 265717

URL: https://gcc.gnu.org/viewcvs?rev=265717&root=gcc&view=rev
Log:
2018-11-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46020
    * gfortran.dg/bind_c_usage_32.f90: Really commit.


Added:
    trunk/gcc/testsuite/gfortran.dg/bind_c_usage_32.f90
Comment 11 Thomas Koenig 2018-11-01 12:02:00 UTC
Author: tkoenig
Date: Thu Nov  1 12:00:59 2018
New Revision: 265719

URL: https://gcc.gnu.org/viewcvs?rev=265719&root=gcc&view=rev
Log:
2018-11-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/46020
	* decl.c (verify_bind_c_sym): Improve error message.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
Comment 12 Thomas Koenig 2018-11-01 12:07:06 UTC
I don't think there is anything left to fix. Closing.
Comment 13 Thomas Koenig 2018-11-01 18:42:00 UTC
Author: tkoenig
Date: Thu Nov  1 18:41:28 2018
New Revision: 265727

URL: https://gcc.gnu.org/viewcvs?rev=265727&root=gcc&view=rev
Log:
2018-11-01  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46020
    * gfortran.dg/bind_c_18.f90: Adjust error message.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/bind_c_18.f90
Comment 14 Thomas Koenig 2018-11-02 20:21:23 UTC
Author: tkoenig
Date: Fri Nov  2 20:20:43 2018
New Revision: 265757

URL: https://gcc.gnu.org/viewcvs?rev=265757&root=gcc&view=rev
Log:
2018-11-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

    PR fortran/46020
    * decl.c (verify_bind_c_sym): Remove unnecessary space
    in error message.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c