[cfe-dev] [libcxx/test] Puzzling floating point behaviour

Marc Glisse marc.glisse at inria.fr
Sat Dec 10 13:40:35 PST 2011


On Sat, 10 Dec 2011, Howard Hinnant wrote:

> On Dec 10, 2011, at 3:59 PM, Marc Glisse wrote:
>
>> On Sat, 10 Dec 2011, Howard Hinnant wrote:
>>
>>> On Dec 10, 2011, at 2:57 PM, Marc Glisse wrote:
>>>
>>>> On Sat, 10 Dec 2011, Howard Hinnant wrote:
>>>>
>>>>> In <math.h> you have:
>>>>>
>>>>> double exp(double);
>>>>> double sin(double);
>>>>> double cos(double);
>>>>>
>>>>> In <cmath> you *additionally* have:
>>>>>
>>>>> namespace std
>>>>> {
>>>>> float exp(float);
>>>>> double exp(double);
>>>>> long double exp(long double);
>>>>>
>>>>> float sin(float);
>>>>> double sin(double);
>>>>> long double sin(long double);
>>>>>
>>>>> float cos(float);
>>>>> double cos(double);
>>>>> long double cos(long double);
>>>>> }
>>>>
>>>> We do agree that this is illegal, even in C++11, right?
>>>
>>> No.
>>>
>>> D.5  C standard library headers  [depr.c.headers]
>>>
>>> 1 ...
>>>
>>> 2 Every C header, each of which has a name of the form name.h, behaves as if each name placed in the standard library namespace by the corresponding cname header is placed within the global namespace scope. It is unspecified whether these names are first declared or defined within namespace scope (3.3.6) of the namespace std and are then injected into the global namespace scope by explicit using-declarations (7.3.3).
>>>
>>> 3 [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the namespace std. It may also provide these names within the global namespace. The header <stdlib.h> assuredly provides the same declarations and definitions within the global namespace, much as in the C Standard. It may also provide these names within the namespace std. — end example ]
>>
>> As far as I can tell, that allows you to declare functions in the global
>> namespace, but not to omit half of the declarations. It thought it was a
>> well-known defect that the change made in C++11 still didn't make the
>> plain C headers valid in C++, so I am a bit surprised at your reaction...
>
> Is your complaint with <math.h> or <cmath>?

math.h, sorry for not being more precise.
(I have not tried to interpret whether the wording allows cmath to leave 
the global namespace with only half the overloads declared, but that's a 
different problem)

-- 
Marc Glisse



More information about the cfe-dev mailing list