Bug 48303 - [Legacy] Support Character constants in DATA statement for non-character variables
Summary: [Legacy] Support Character constants in DATA statement for non-character vari...
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: documentation
Depends on:
Blocks:
 
Reported: 2011-03-27 18:28 UTC by Tobias Burnus
Modified: 2020-01-08 11:24 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-03-27 23:08:42


Attachments
Longer example (812 bytes, text/plain)
2011-03-27 19:18 UTC, Tobias Burnus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-03-27 18:28:48 UTC
Reported on freenode's #fortran.

The following program uses:
      DATA ZERO,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,
     & RNINE,TEN/'-','1','2','3','4','5','6','7','8','9','T'/

which almost all my compilers accept as vendor extension; however, gfortran only accepts Hollerith constants (even more common vendor extension) in DATA:

      DATA ZERO,ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,
     & RNINE,TEN/1H-,1H1,1H2,1H3,1H4,1H5,1H6,1H7,1H8,1H9,1HT/

Expected: As -std=legacy extension, also accept in DATA character literals.

The full program is the first one in the list at http://www.netl.doe.gov/technologies/oil-gas/software/simulat.html
Comment 1 Tobias Burnus 2011-03-27 19:18:32 UTC
Created attachment 23784 [details]
Longer example
Comment 2 Steven Bosscher 2011-03-27 22:01:04 UTC
What are the semantics supposed to be of this extension? Make the variables assigned in the data implicitly typed CHARACTER?
Comment 3 Steven Bosscher 2011-03-27 23:08:20 UTC
Interpret them as Hollerith constants? Something like this extremely crude code from the hip:

  /* Only DATA Statements come here.  */
  if (!conform)
    {
      /* Numeric can be converted to any other numeric. And Hollerith can be
         converted to any other type.  */
      if ((gfc_numeric_ts (&lvalue->ts) && gfc_numeric_ts (&rvalue->ts))
          || rvalue->ts.type == BT_HOLLERITH)
        return SUCCESS;

      if (lvalue->ts.type == BT_LOGICAL && rvalue->ts.type == BT_LOGICAL)
        return SUCCESS;

      /* In legacy mode, accept CHARACTER data, interpreted as a Hollerith
         constant.  */
      if (lvalue->ts.type != rvalue->ts.type
          && rvalue->ts.type == BT_CHARACTER
          && rvalue->ts.kind == gfc_default_character_kind)
        {
          gfc_expr *e;
          unsigned i, l;

          if (gfc_notify_std (GFC_STD_LEGACY, "Shame on you at %C ")
              == FAILURE)
            return FAILURE;

          l = rvalue->value.character.length;
          e = gfc_get_constant_expr (BT_HOLLERITH, gfc_default_character_kind,
                                     &rvalue->where);
          e->representation.string = XCNEWVEC (char, l + 1);
          for (i = 0; i < l; i++)
            {
              gfc_char_t c = rvalue->value.character.string[i];
              e->representation.string[i] = (char) c;
            }
          *rvalue = *e; /* ??? Not sure how to replace rvalue with the new e */
          return SUCCESS;
        }
Comment 4 Dominique d'Humieres 2013-06-22 13:28:37 UTC
No activity since more than two years. IMO this should go under the section

6.2 Extensions not implemented in GNU Fortran

of the manual. I can submit a draft patch for this PR if someone is will to fix
my Frenglish and formatting issues and do the commit.
Comment 5 Thomas Koenig 2019-09-18 17:45:14 UTC
(In reply to Dominique d'Humieres from comment #4)
> No activity since more than two years. IMO this should go under the section
> 
> 6.2 Extensions not implemented in GNU Fortran
> 
> of the manual. I can submit a draft patch for this PR if someone is will to
> fix
> my Frenglish and formatting issues and do the commit.

Hi,

just going through some WAITING bugs... do you still plan to do this?
If not, I can also do this.
Comment 6 MarkEggleston 2019-11-20 14:13:39 UTC
See

https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=277975

I'm pretty sure this can be closed as fixed.
Comment 7 markeggleston 2020-01-08 11:24:52 UTC
Requires -fdec or -fdec-char-conversions

trunk (10.0).