public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rsa at us dot ibm.com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/51364] C++ interoperability with ISO-C extension DFP types requires explicit typedefs.
Date: Wed, 18 Jan 2012 20:21:00 -0000	[thread overview]
Message-ID: <bug-51364-4-pjW1ufFFVb@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-51364-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51364

--- Comment #12 from Ryan S. Arnold <rsa at us dot ibm.com> 2012-01-18 20:00:08 UTC ---
Returning to the bug report at hand...

In my version of float.h I have the following (which aligns with the typedef
definitions in the std::decimal namespace).  This works just fine for _Decimal*
and decimal* compatibility:

typedef float _Decimal32 __attribute__((mode(SD)));
typedef float _Decimal64 __attribute__((mode(DD)));
typedef float _Decimal128 __attribute__((mode(TD)));

But the TR indicates that the following compatibility types are to be provided
instead so I attempted to replace what I have with these:

3.4.2 Header <float.h> synopsis  
      // C-compatibility convenience typedefs:  
      typedef std::decimal::decimal32  _Decimal32;  
      typedef std::decimal::decimal64  _Decimal64;  
      typedef std::decimal::decimal128 _Decimal128;

I've found that when this is provided in float.h (my own overloaded float.h) I
get the following warning:

warning: format '%Df' expects type '_Decimal64', but argument 2 has type
'_Decimal64'

And more importantly, the following error:

../libdfp-decimal/dfp/decimal/decimal:241:32: error: no matching function for
call to 'std::decimal::decimal32::__setval(_Decimal32&)'
/opt/at4.0/lib/gcc/powerpc64-linux/4.5.4/../../../../include/c++/4.5.4/decimal/decimal:304:10:
note: candidate is: void
std::decimal::decimal32::__setval(std::decimal::decimal32::__decfloat32)

Where the error identified code is doing the following:


  template <class charT, class traits>
    inline std::basic_istream<charT, traits> &
      operator>>(std::basic_istream<charT, traits> & is, decimal32 & d)
      {
        char buf[CHAR_MAX];
        memset(buf, '\0', CHAR_MAX);
        is.read(buf,CHAR_MAX);
--->    d.__setval(strtod32(buf, NULL));
        return is;
      }
(Note: This error isn't encountered when _Decimal32 is typedefed to float
_Decimal32 __attribute__((mode(SD)));).

This is how I'd expect to be able to set the actual value in the decimal32
number (coming out of a routine that returns a C-style _Decimal32) but this
obviously isn't correct since _Decimal32 is recognized by the C++ compiler as a
std::decimal::decimal32 typedef and is not type compatible with
std::decimal:decimal32::__decfloat32.

Interestingly, adding the following to the system decimal/decimal
std::decimal::decimal32 class definition makes the error go away:

operator __decfloat32() { return __val; }

I presume what is happening is that _Decimal32 is recognized as
std::decimal::decimal32 (due to the typedef) and then the __decfloat32 operator
is applied to it and it then magically matches the __setval() prototype and the
error is silenced.  The problem is, it doesn't work, i.e., the assignment never
makes it way into __val correctly.

So I'm not sure what to make of the TR's requirement.  It seems that the
typedef float _Decimal32 __attribute__((mode(SD))); method is the correct one.


      parent reply	other threads:[~2012-01-18 20:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-30 18:58 [Bug c++/51364] New: " rsa at us dot ibm.com
2011-11-30 19:09 ` [Bug c++/51364] " redi at gcc dot gnu.org
2011-11-30 21:46 ` janis at gcc dot gnu.org
2011-11-30 21:46 ` rsa at us dot ibm.com
2011-11-30 21:59 ` janis at gcc dot gnu.org
2011-12-09 16:06 ` rsa at us dot ibm.com
2011-12-17 21:14 ` mingodad at gmail dot com
2011-12-18  6:28 ` janis at gcc dot gnu.org
2011-12-19  0:10 ` mingodad at gmail dot com
2011-12-19  0:27 ` redi at gcc dot gnu.org
2011-12-19  3:33 ` mingodad at gmail dot com
2011-12-19 20:45 ` janis at gcc dot gnu.org
2012-01-18 20:21 ` rsa at us dot ibm.com [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-51364-4-pjW1ufFFVb@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).