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.

Reply via email to