diff mbox

Define iszero as a function template for C++ [BZ #20715]

Message ID c838d4f1-99fa-6736-532e-1db62d5d5ff8@redhat.com
State New
Headers show

Commit Message

Florian Weimer Oct. 22, 2016, 3:34 p.m. UTC
On 10/21/2016 06:31 PM, Florian Weimer wrote:
> On 10/21/2016 06:23 PM, Joseph Myers wrote:

>> On Fri, 21 Oct 2016, Florian Weimer wrote:

>>

>>> On 10/21/2016 06:12 PM, Joseph Myers wrote:

>>>> On Fri, 21 Oct 2016, Florian Weimer wrote:

>>>>

>>>>> Tested on x86_64, ppc64, ppc64le, s390x, aarch64.

>>>>>

>>>>> I'm not sure if the new test is particularly meaningful, but at

>>>>> least it

>>>>> catches syntax errors in <math.h>.

>>>>

>>>> This seems fine to me (with negative zero included in the testcase),

>>>

>>> Oh.  How do I get a negative zero?  Would T{-0.0} be sufficient?  Or

>>> should I

>>

>> Yes, T{-0.0} or -T{0} should suffice.

>

> Thanks.  Here is what I've committed.  Everything is optimized away

> anyway (but I deliberately introduced a bug to make sure the test still

> tests something).


I had to commit the attached follow-on fix to make

extern "C" {
#include <math.h>
}

work again.

Florian
diff mbox

Patch

math.h: Wrap C++ bits in extern "C++"

It is still common to include system header files in an extern "C"
block.  This means that exiting <math.h>'s own extern "C" block
is not sufficient to get back to C++ mode.  Use an extern "C++"
wrapper instead.

2016-10-22  Florian Weimer  <fweimer@redhat.com>

	* math/math.h [__cplusplus] (iszero): Wrap C++ bits in extern
	"C++", to override a potential extern "C" directive around the
	header file inclusion.

diff --git a/math/math.h b/math/math.h
index 0220d08..7c0c709 100644
--- a/math/math.h
+++ b/math/math.h
@@ -342,7 +342,7 @@  enum
 #   define iszero(x) (((__typeof (x)) (x)) == 0)
 #  endif
 # else	/* __cplusplus */
-__END_DECLS
+extern "C++" {
 template <class __T> inline bool
 iszero (__T __val)
 {
@@ -352,7 +352,7 @@  iszero (__T __val)
   return __val == 0;
 #  endif
 }
-__BEGIN_DECLS
+} /* extern C++ */
 # endif	/* __cplusplus */
 #endif /* Use IEC_60559_BFP_EXT.  */