public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h
@ 2016-01-08 19:19 Jonathan Wakely
  2016-01-19 21:44 ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2016-01-08 19:19 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 3184 bytes --]

This resolves the longstanding issue that #include <math.h> uses the C
library header, which on most targets doesn't declare the additional
overloads required by C++11 26.8 [c.math], and similarly for
<stdlib.h>.

With this patch libstdc++ provides its own <math.h> and <stdlib.h>
wrappers, which are equivalent to <cmath> or <cstdlib> followed by
using-directives for all standard names. This means there are no more
inconsistencies in the contents of the <cxxx> and <xxx.h> headers.

This check might be surprising:
#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS

Checking for __cplusplus is necessary to bootstrap because the new
libstdc++ math.h wrapper is in the header search path when
libstdc++/cp-demangle.c is built, but that's a C file and so wants the
C header not the wrapper.

The second condition ensures that when the <cxxx> headers say
#include_next <xxx.h> they really find the C library version, not some
other libstdc++ <xxx.h> wrapper that is already installed elsewhere on
the system. That can happen if you build libstdc++ with this patch and
install it, then build again with the same prefix. The directory
$PREFIX/include/c++/6.0.0 ends up in the header search path when
running the testsuite, and without _GLIBCXX_INCLUDE_NEXT_C_HEADERS
the #include_next <math.h> finds the previously installed wrapper
$PREFIX/include/c++/6.0.0/math.h, which then tries to #include <cmath>
again and add using-directives for functions which haven't been
declared yet because we haven't found the real C library header.

It's possible that this is only a problem when building and testing
libstdc++ itself, so we could remove the check and solve the problem
by adjusting paths used during build/test so that our own wrapper is
never found. I'm not confident of that, so it seems safer to have this
macro so that <cstdlib> and <cmath> can define it to ensure they get
the real C header, even if they go through one or more wrappers to get
there!

It's also possible that include/c/cstdlib and include/c/cmath need to
#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS before they use #include_next,
to prevent them finding the wrapper. I have only really considered  the
--enable-cheaders=c_global configuration, because I don't understand
the other ones.

This patch cannot be applied without the patch at
https://gcc.gnu.org/ml/gcc-patches/2016-01/msg00416.html because with
the new <math.h> wrapper we *always* hit the bug where <cmath> #undefs
the C99 macros and then collides with the obsolete isinf and isnan
functions.

The second patch (which requires both the previous patches) then
implements the proposed resolution of LWG 2294, ensuring that all
std::abs() overloads for integers and floating-point types are
available when you include either of <cmath> or <cstdlib>. That issue
is still open (and LWG 2291 adds a constraint on the generic
std::abs(T) function template which I haven't implemented yet). I
might commit it anyway, as the committee's direction is clear.

All tested x86_64-linux and x86_64-freebsd10.2, I don't plan to commit
any of these patches until next week, to give people time to digest
them and point out any problems I've missed.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 8415 bytes --]

commit ead087854b669262ee258ff3835d96a593dd9e65
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Jan 8 15:43:14 2016 +0000

    Add C++-conforming wrappers for stdlib.h and math.h
    
    	PR libstdc++/14608
    	PR libstdc++/60401
    	* include/Makefile.am: Use c_compatibility math.h and stdlib.h for
    	--enable-cheaders=c_global configs.
    	* include/Makefile.in: Regenerate.
    	* include/c_compatibility/math.h: Remove obsolete _GLIBCXX_NAMESPACE_C
    	test and allow inclusion from C files.
    	* include/c_compatibility/stdlib.h: Likewise. Support freestanding.
    	(at_quick_exit, quick_exit): Add using directives.
    	* include/c_global/cmath: Use #include_next for math.h.
    	* include/c_global/cstdlib: Use #include_next for stdlib.h.
    	* testsuite/26_numerics/headers/cmath/14608.cc: New.
    	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc:
    	Remove xfail for most targets.
    	* testsuite/26_numerics/headers/cstdlib/60401.cc: New.

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index b0a9373..84cb8b1 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -739,7 +739,9 @@ if GLIBCXX_C_HEADERS_C_GLOBAL
 c_compatibility_headers = \
 	${c_compatibility_srcdir}/complex.h \
 	${c_compatibility_srcdir}/fenv.h \
-	${c_compatibility_srcdir}/tgmath.h
+	${c_compatibility_srcdir}/tgmath.h \
+	${c_compatibility_srcdir}/math.h \
+	${c_compatibility_srcdir}/stdlib.h
 endif
 
 if GLIBCXX_C_HEADERS_C
diff --git a/libstdc++-v3/include/c_compatibility/math.h b/libstdc++-v3/include/c_compatibility/math.h
index 7617a31..67f5ef1 100644
--- a/libstdc++-v3/include/c_compatibility/math.h
+++ b/libstdc++-v3/include/c_compatibility/math.h
@@ -26,12 +26,15 @@
  *  This is a Standard C++ Library header.
  */
 
-#include <cmath>
 
 #ifndef _GLIBCXX_MATH_H
 #define _GLIBCXX_MATH_H 1
 
-#ifdef _GLIBCXX_NAMESPACE_C
+#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+# include_next <math.h>
+#else
+# include <cmath>
+
 using std::abs;
 using std::acos;
 using std::asin;
@@ -72,5 +75,4 @@ using std::isunordered;
 #endif
 
 #endif
-
 #endif
diff --git a/libstdc++-v3/include/c_compatibility/stdlib.h b/libstdc++-v3/include/c_compatibility/stdlib.h
index bd666d6..bd72580 100644
--- a/libstdc++-v3/include/c_compatibility/stdlib.h
+++ b/libstdc++-v3/include/c_compatibility/stdlib.h
@@ -26,25 +26,37 @@
  *  This is a Standard C++ Library header.
  */
 
-#include <cstdlib>
-
 #ifndef _GLIBCXX_STDLIB_H
 #define _GLIBCXX_STDLIB_H 1
 
-#ifdef _GLIBCXX_NAMESPACE_C
+#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+# include_next <stdlib.h>
+#else
+# include <cstdlib>
+
+using std::abort;
+using std::atexit;
+using std::exit;
+#if __cplusplus >= 201103L
+# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
+  using std::at_quick_exit;
+# endif
+# ifdef _GLIBCXX_HAVE_QUICK_EXIT
+  using std::quick_exit;
+# endif
+#endif
+
+#if _GLIBCXX_HOSTED
 using std::div_t;
 using std::ldiv_t;
 
-using std::abort;
 using std::abs;
-using std::atexit;
 using std::atof;
 using std::atoi;
 using std::atol;
 using std::bsearch;
 using std::calloc;
 using std::div;
-using std::exit;
 using std::free;
 using std::getenv;
 using std::labs;
@@ -66,3 +78,4 @@ using std::wctomb;
 #endif
 
 #endif
+#endif
diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath
index 6269e32..7eed8e1 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -41,7 +41,9 @@
 #include <bits/c++config.h>
 #include <bits/cpp_type_traits.h>
 #include <ext/type_traits.h>
-#include <math.h>
+#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+#include_next <math.h>
+#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 
 #ifndef _GLIBCXX_CMATH
 #define _GLIBCXX_CMATH 1
diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib
index 0f506a4..44b6e5c 100644
--- a/libstdc++-v3/include/c_global/cstdlib
+++ b/libstdc++-v3/include/c_global/cstdlib
@@ -69,7 +69,11 @@ namespace std
 
 #else
 
-#include <stdlib.h>
+// Need to ensure this finds the C library's <stdlib.h> not a libstdc++
+// wrapper that might already be installed later in the include search path.
+#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+#include_next <stdlib.h>
+#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 
 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
 #undef abort
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/14608.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/14608.cc
new file mode 100644
index 0000000..65f5c6c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/14608.cc
@@ -0,0 +1,38 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <cmath>
+// Also make names from <cmath> available in the global namespace:
+#include <math.h>
+
+bool foo(double d)
+{
+  return ::isfinite(d); // PR libstdc++/14608
+}
+
+int bar(double d)
+{
+  return ::signbit(d); // PR libstdc++/44611
+}
+
+constexpr bool is_double(double) { return true; }
+template<typename T> constexpr bool is_double(T) { return false; }
+using type = decltype(::abs(1.5));
+static_assert(is_double(type{}), "::abs(double) overload exists in <math.h>");
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc
index ead3018..cbced7d 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc
@@ -17,12 +17,10 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-do compile }
+// { dg-do compile { xfail uclibc } }
+// { dg-excess-errors "" { target uclibc } }
 // { dg-add-options no_pch }
 
-// { dg-xfail-if "" { { *-*-linux* *-*-gnu* *-*-darwin* *-*-solaris2.1[01]* hppa*-*-hpux* *-*-mingw* *-*-aix* } || { uclibc || newlib } } { "*" } { "" } }
-// { dg-excess-errors "" { target { { *-*-linux* *-*-gnu* *-*-darwin* *-*-solaris2.1[01]* hppa*-*-hpux* *-*-mingw* *-*-aix* } || { uclibc || newlib } } } }
-
 #include <math.h>
 
 void fpclassify() { }
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cstdlib/60401.cc b/libstdc++-v3/testsuite/26_numerics/headers/cstdlib/60401.cc
new file mode 100644
index 0000000..f0cff33
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cstdlib/60401.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// PR libstdc++/60401
+
+#include <stdlib.h>
+
+constexpr bool is_long(long) { return true; }
+template<typename T> constexpr bool is_long(T) { return false; }
+using type = decltype(::abs(1L));
+static_assert(is_long(type{}), "::abs(long) overload exists in <stdlib.h>");

[-- Attachment #3: lwg2294.txt --]
[-- Type: text/plain, Size: 5689 bytes --]

commit f4bd35b818f0acbbb879fd7ca9aa6bd7ec955b5c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jan 7 16:01:09 2016 +0000

    Define all std::abs overloads in both <cmath> and <cstdlib>
    
    	* include/Makefile.am: Add bits/std_abs.h.
    	* include/Makefile.in: Regenerate.
    	* include/bits/std_abs.h: New header defining all required overloads
    	of std::abs in one place (LWG 2294).
    	* include/c_global/cmath (abs(double), abs(float), abs(long double)):
    	Move to bits/std_abs.h.
    	* include/c_global/cstdlib (abs(long), abs(long long)): Move to
    	bits/std_abs.h.

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 84cb8b1..bd7c8d7 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -122,6 +122,7 @@ bits_headers = \
 	${bits_srcdir}/mask_array.h \
 	${bits_srcdir}/memoryfwd.h \
 	${bits_srcdir}/move.h \
+	${bits_srcdir}/std_abs.h \
 	${bits_srcdir}/std_mutex.h \
 	${bits_srcdir}/ostream.tcc \
 	${bits_srcdir}/ostream_insert.h \
diff --git a/libstdc++-v3/include/bits/std_abs.h b/libstdc++-v3/include/bits/std_abs.h
new file mode 100644
index 0000000..beb09b9
--- /dev/null
+++ b/libstdc++-v3/include/bits/std_abs.h
@@ -0,0 +1,80 @@
+// -*- C++ -*- C library enhancements header.
+
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file include/bits/std_abs.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{cmath, cstdlib}
+ */
+
+#ifndef _GLIBCXX_BITS_STD_ABS_H
+#define _GLIBCXX_BITS_STD_ABS_H
+
+#pragma GCC system_header
+
+#include <bits/c++config.h>
+#include_next <stdlib.h>
+
+#ifdef __CORRECT_ISO_CPP_MATH_H_PROTO
+# include_next <math.h>
+#endif
+
+#undef abs
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  using ::abs;
+
+#ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
+  inline long
+  abs(long __i) { return __builtin_labs(__i); }
+#endif
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  inline long long
+  abs(long long __x) { return __builtin_llabs (__x); }
+#endif
+
+// _GLIBCXX_RESOLVE_LIB_DEFECTS
+// 2294. <cstdlib> should declare abs(double)
+
+#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
+  inline _GLIBCXX_CONSTEXPR double
+  abs(double __x)
+  { return __builtin_fabs(__x); }
+
+  inline _GLIBCXX_CONSTEXPR float
+  abs(float __x)
+  { return __builtin_fabsf(__x); }
+
+  inline _GLIBCXX_CONSTEXPR long double
+  abs(long double __x)
+  { return __builtin_fabsl(__x); }
+#endif
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace
+
+#endif // _GLIBCXX_BITS_STD_ABS_H
diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath
index 7eed8e1..095ecd7 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -43,6 +43,7 @@
 #include <ext/type_traits.h>
 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 #include_next <math.h>
+#include <bits/std_abs.h>
 #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 
 #ifndef _GLIBCXX_CMATH
@@ -78,22 +79,6 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
-  inline _GLIBCXX_CONSTEXPR double
-  abs(double __x)
-  { return __builtin_fabs(__x); }
-#endif
-
-#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
-  inline _GLIBCXX_CONSTEXPR float
-  abs(float __x)
-  { return __builtin_fabsf(__x); }
-
-  inline _GLIBCXX_CONSTEXPR long double
-  abs(long double __x)
-  { return __builtin_fabsl(__x); }
-#endif
-
   template<typename _Tp>
     inline _GLIBCXX_CONSTEXPR
     typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value,
diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib
index 44b6e5c..bba4ce5 100644
--- a/libstdc++-v3/include/c_global/cstdlib
+++ b/libstdc++-v3/include/c_global/cstdlib
@@ -73,6 +73,7 @@ namespace std
 // wrapper that might already be installed later in the include search path.
 #define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 #include_next <stdlib.h>
+#include <bits/std_abs.h>
 #undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 
 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
@@ -166,18 +167,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif // _GLIBCXX_USE_WCHAR_T
 
 #ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO
-  inline long
-  abs(long __i) { return __builtin_labs(__i); }
-
   inline ldiv_t
   div(long __i, long __j) { return ldiv(__i, __j); }
 #endif
 
-#ifdef _GLIBCXX_USE_LONG_LONG
-  inline long long
-  abs(long long __x) { return __builtin_llabs (__x); }
-#endif
-
 #if defined(__GLIBCXX_TYPE_INT_N_0)
   inline __GLIBCXX_TYPE_INT_N_0
   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h
  2016-01-08 19:19 [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h Jonathan Wakely
@ 2016-01-19 21:44 ` Jonathan Wakely
  2016-01-20 12:34   ` [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib Jonathan Wakely
  2016-01-20 16:18   ` [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h Dominik Vogt
  0 siblings, 2 replies; 8+ messages in thread
From: Jonathan Wakely @ 2016-01-19 21:44 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

On 08/01/16 19:18 +0000, Jonathan Wakely wrote:
>This resolves the longstanding issue that #include <math.h> uses the C
>library header, which on most targets doesn't declare the additional
>overloads required by C++11 26.8 [c.math], and similarly for
><stdlib.h>.
>
>With this patch libstdc++ provides its own <math.h> and <stdlib.h>
>wrappers, which are equivalent to <cmath> or <cstdlib> followed by
>using-directives for all standard names. This means there are no more
>inconsistencies in the contents of the <cxxx> and <xxx.h> headers.

Tested x86_64-linux, powerpc64le-linux, powerpc-aix,
x86_64-freebsd10.2, x86_64-dragonfly4.2

Committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 9259 bytes --]

commit 55b627c6c6b84fa05d01005bc7bff0860a280cc0
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jan 18 18:28:58 2016 +0000

    Add C++-conforming wrappers for stdlib.h and math.h
    
    	PR libstdc++/14608
    	PR libstdc++/60401
    	* include/Makefile.am: Use c_compatibility math.h and stdlib.h for
    	--enable-cheaders=c_global configs.
    	* include/Makefile.in: Regenerate.
    	* include/c_compatibility/math.h: Remove obsolete _GLIBCXX_NAMESPACE_C
    	test and allow inclusion from C files.
    	* include/c_compatibility/stdlib.h: Likewise. Support freestanding.
    	(at_quick_exit, quick_exit): Add using directives.
    	* include/c_global/cmath: Use #include_next for math.h.
    	* include/c_global/cstdlib: Use #include_next for stdlib.h.
    	* testsuite/26_numerics/headers/cmath/14608.cc: New.
    	* testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc:
    	Remove xfail for most targets.
    	* testsuite/26_numerics/headers/cstdlib/60401.cc: New.

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 39327d9..573f057 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -740,7 +740,9 @@ if GLIBCXX_C_HEADERS_C_GLOBAL
 c_compatibility_headers = \
 	${c_compatibility_srcdir}/complex.h \
 	${c_compatibility_srcdir}/fenv.h \
-	${c_compatibility_srcdir}/tgmath.h
+	${c_compatibility_srcdir}/tgmath.h \
+	${c_compatibility_srcdir}/math.h \
+	${c_compatibility_srcdir}/stdlib.h
 endif
 
 if GLIBCXX_C_HEADERS_C
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index e74fae8..57f1ec5 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -1023,7 +1023,9 @@ c_compatibility_builddir = .
 @GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@c_compatibility_headers = \
 @GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@	${c_compatibility_srcdir}/complex.h \
 @GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@	${c_compatibility_srcdir}/fenv.h \
-@GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@	${c_compatibility_srcdir}/tgmath.h
+@GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@	${c_compatibility_srcdir}/tgmath.h \
+@GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@	${c_compatibility_srcdir}/math.h \
+@GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@	${c_compatibility_srcdir}/stdlib.h
 
 @GLIBCXX_C_HEADERS_C_STD_TRUE@c_compatibility_headers = 
 @GLIBCXX_C_HEADERS_C_TRUE@c_compatibility_headers = \
diff --git a/libstdc++-v3/include/c_compatibility/math.h b/libstdc++-v3/include/c_compatibility/math.h
index 7617a31..67f5ef1 100644
--- a/libstdc++-v3/include/c_compatibility/math.h
+++ b/libstdc++-v3/include/c_compatibility/math.h
@@ -26,12 +26,15 @@
  *  This is a Standard C++ Library header.
  */
 
-#include <cmath>
 
 #ifndef _GLIBCXX_MATH_H
 #define _GLIBCXX_MATH_H 1
 
-#ifdef _GLIBCXX_NAMESPACE_C
+#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+# include_next <math.h>
+#else
+# include <cmath>
+
 using std::abs;
 using std::acos;
 using std::asin;
@@ -72,5 +75,4 @@ using std::isunordered;
 #endif
 
 #endif
-
 #endif
diff --git a/libstdc++-v3/include/c_compatibility/stdlib.h b/libstdc++-v3/include/c_compatibility/stdlib.h
index bd666d6..bd72580 100644
--- a/libstdc++-v3/include/c_compatibility/stdlib.h
+++ b/libstdc++-v3/include/c_compatibility/stdlib.h
@@ -26,25 +26,37 @@
  *  This is a Standard C++ Library header.
  */
 
-#include <cstdlib>
-
 #ifndef _GLIBCXX_STDLIB_H
 #define _GLIBCXX_STDLIB_H 1
 
-#ifdef _GLIBCXX_NAMESPACE_C
+#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+# include_next <stdlib.h>
+#else
+# include <cstdlib>
+
+using std::abort;
+using std::atexit;
+using std::exit;
+#if __cplusplus >= 201103L
+# ifdef _GLIBCXX_HAVE_AT_QUICK_EXIT
+  using std::at_quick_exit;
+# endif
+# ifdef _GLIBCXX_HAVE_QUICK_EXIT
+  using std::quick_exit;
+# endif
+#endif
+
+#if _GLIBCXX_HOSTED
 using std::div_t;
 using std::ldiv_t;
 
-using std::abort;
 using std::abs;
-using std::atexit;
 using std::atof;
 using std::atoi;
 using std::atol;
 using std::bsearch;
 using std::calloc;
 using std::div;
-using std::exit;
 using std::free;
 using std::getenv;
 using std::labs;
@@ -66,3 +78,4 @@ using std::wctomb;
 #endif
 
 #endif
+#endif
diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath
index c689b31..45e40ab3 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -41,7 +41,9 @@
 #include <bits/c++config.h>
 #include <bits/cpp_type_traits.h>
 #include <ext/type_traits.h>
-#include <math.h>
+#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+#include_next <math.h>
+#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 
 #ifndef _GLIBCXX_CMATH
 #define _GLIBCXX_CMATH 1
diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib
index 0f506a4..44b6e5c 100644
--- a/libstdc++-v3/include/c_global/cstdlib
+++ b/libstdc++-v3/include/c_global/cstdlib
@@ -69,7 +69,11 @@ namespace std
 
 #else
 
-#include <stdlib.h>
+// Need to ensure this finds the C library's <stdlib.h> not a libstdc++
+// wrapper that might already be installed later in the include search path.
+#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
+#include_next <stdlib.h>
+#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
 
 // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
 #undef abort
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/14608.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/14608.cc
new file mode 100644
index 0000000..65f5c6c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/14608.cc
@@ -0,0 +1,38 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+#include <cmath>
+// Also make names from <cmath> available in the global namespace:
+#include <math.h>
+
+bool foo(double d)
+{
+  return ::isfinite(d); // PR libstdc++/14608
+}
+
+int bar(double d)
+{
+  return ::signbit(d); // PR libstdc++/44611
+}
+
+constexpr bool is_double(double) { return true; }
+template<typename T> constexpr bool is_double(T) { return false; }
+using type = decltype(::abs(1.5));
+static_assert(is_double(type{}), "::abs(double) overload exists in <math.h>");
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc
index ead3018..cbced7d 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc
@@ -17,12 +17,10 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-do compile }
+// { dg-do compile { xfail uclibc } }
+// { dg-excess-errors "" { target uclibc } }
 // { dg-add-options no_pch }
 
-// { dg-xfail-if "" { { *-*-linux* *-*-gnu* *-*-darwin* *-*-solaris2.1[01]* hppa*-*-hpux* *-*-mingw* *-*-aix* } || { uclibc || newlib } } { "*" } { "" } }
-// { dg-excess-errors "" { target { { *-*-linux* *-*-gnu* *-*-darwin* *-*-solaris2.1[01]* hppa*-*-hpux* *-*-mingw* *-*-aix* } || { uclibc || newlib } } } }
-
 #include <math.h>
 
 void fpclassify() { }
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cstdlib/60401.cc b/libstdc++-v3/testsuite/26_numerics/headers/cstdlib/60401.cc
new file mode 100644
index 0000000..f0cff33
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cstdlib/60401.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// PR libstdc++/60401
+
+#include <stdlib.h>
+
+constexpr bool is_long(long) { return true; }
+template<typename T> constexpr bool is_long(T) { return false; }
+using type = decltype(::abs(1L));
+static_assert(is_long(type{}), "::abs(long) overload exists in <stdlib.h>");

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib
  2016-01-19 21:44 ` Jonathan Wakely
@ 2016-01-20 12:34   ` Jonathan Wakely
  2016-01-21 13:39     ` Jonathan Wakely
  2016-01-20 16:18   ` [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h Dominik Vogt
  1 sibling, 1 reply; 8+ messages in thread
From: Jonathan Wakely @ 2016-01-20 12:34 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 873 bytes --]

On 19/01/16 21:43 +0000, Jonathan Wakely wrote:
>On 08/01/16 19:18 +0000, Jonathan Wakely wrote:
>>This resolves the longstanding issue that #include <math.h> uses the C
>>library header, which on most targets doesn't declare the additional
>>overloads required by C++11 26.8 [c.math], and similarly for
>><stdlib.h>.
>>
>>With this patch libstdc++ provides its own <math.h> and <stdlib.h>
>>wrappers, which are equivalent to <cmath> or <cstdlib> followed by
>>using-directives for all standard names. This means there are no more
>>inconsistencies in the contents of the <cxxx> and <xxx.h> headers.

The new wrappers might get included as:

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

which then includes <cstdlib> inside the extern "C" block, so we need
to ensure that the definitions in <cstdlib> get the right language
linkage.

Tested powerpc64le-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3775 bytes --]

commit d5175d037f6d1a5951d3a023dca71bed16ec0434
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jan 20 11:41:47 2016 +0000

    Ensure C++ language linkage in cmath and cstdlib
    
    	PR libstdc++/69386
    	* include/c_global/ccomplex: Ensure C++ language linkage.
    	* include/c_global/cmath: Likewise.
    	* include/c_global/cstdlib: Likewise.
    	* include/c_global/ctgmath: Likewise.
    	* testsuite/17_intro/headers/c++2011/linkage.cc: New.

diff --git a/libstdc++-v3/include/c_global/ccomplex b/libstdc++-v3/include/c_global/ccomplex
index 8879e20..df2e413 100644
--- a/libstdc++-v3/include/c_global/ccomplex
+++ b/libstdc++-v3/include/c_global/ccomplex
@@ -35,6 +35,8 @@
 # include <bits/c++0x_warning.h>
 #endif
 
+extern "C++" {
 #include <complex>
+}
 
 #endif
diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath
index 45e40ab3..c4ee3f5 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -74,6 +74,8 @@
 #undef tan
 #undef tanh
 
+extern "C++"
+{
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -1790,4 +1792,6 @@ _GLIBCXX_END_NAMESPACE_VERSION
 #  include <bits/specfun.h>
 #endif
 
+} // extern "C++"
+
 #endif
diff --git a/libstdc++-v3/include/c_global/cstdlib b/libstdc++-v3/include/c_global/cstdlib
index 44b6e5c..1ba5fb7 100644
--- a/libstdc++-v3/include/c_global/cstdlib
+++ b/libstdc++-v3/include/c_global/cstdlib
@@ -115,6 +115,8 @@ namespace std
 #undef wcstombs
 #undef wctomb
 
+extern "C++"
+{
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -272,6 +274,8 @@ namespace std
 
 #endif // _GLIBCXX_USE_C99_STDLIB
 
+} // extern "C++"
+
 #endif // !_GLIBCXX_HOSTED
 
 #endif
diff --git a/libstdc++-v3/include/c_global/ctgmath b/libstdc++-v3/include/c_global/ctgmath
index 2fee958..4314516 100644
--- a/libstdc++-v3/include/c_global/ctgmath
+++ b/libstdc++-v3/include/c_global/ctgmath
@@ -35,7 +35,9 @@
 #  include <bits/c++0x_warning.h>
 #else
 #  include <cmath>
+extern "C++" {
 #  include <complex>
+}
 #endif
 
 #endif 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
new file mode 100644
index 0000000..33e7053
--- /dev/null
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
@@ -0,0 +1,50 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// libstdc++/69386
+
+extern "C"
+{
+#include <assert.h>
+#include <complex.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fenv.h>
+#include <float.h>
+#include <inttypes.h>
+#include <iso646.h>
+#include <limits.h>
+#include <locale.h>
+#include <math.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <tgmath.h>
+#include <time.h>
+#include <uchar.h>
+#include <wchar.h>
+#include <wctype.h>
+}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h
  2016-01-19 21:44 ` Jonathan Wakely
  2016-01-20 12:34   ` [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib Jonathan Wakely
@ 2016-01-20 16:18   ` Dominik Vogt
  2016-01-20 17:45     ` Jonathan Wakely
  1 sibling, 1 reply; 8+ messages in thread
From: Dominik Vogt @ 2016-01-20 16:18 UTC (permalink / raw)
  To: gcc-patches, libstdc++; +Cc: Jonathan Wakely

On Tue, Jan 19, 2016 at 09:43:59PM +0000, Jonathan Wakely wrote:
> On 08/01/16 19:18 +0000, Jonathan Wakely wrote:
> >This resolves the longstanding issue that #include <math.h> uses the C
> >library header, which on most targets doesn't declare the additional
> >overloads required by C++11 26.8 [c.math], and similarly for
> ><stdlib.h>.
> >
> >With this patch libstdc++ provides its own <math.h> and <stdlib.h>
> >wrappers, which are equivalent to <cmath> or <cstdlib> followed by
> >using-directives for all standard names. This means there are no more
> >inconsistencies in the contents of the <cxxx> and <xxx.h> headers.
> 
> Tested x86_64-linux, powerpc64le-linux, powerpc-aix,
> x86_64-freebsd10.2, x86_64-dragonfly4.2
> 
> Committed to trunk.

I think this fix is incomplete.  There are still some test errors
because of missing signatures in the Plumhall testsuite.  Please
check the information I've added to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60401

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt
IBM Germany

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h
  2016-01-20 16:18   ` [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h Dominik Vogt
@ 2016-01-20 17:45     ` Jonathan Wakely
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2016-01-20 17:45 UTC (permalink / raw)
  To: vogt, gcc-patches, libstdc++

[-- Attachment #1: Type: text/plain, Size: 1107 bytes --]

On 20/01/16 17:17 +0100, Dominik Vogt wrote:
>On Tue, Jan 19, 2016 at 09:43:59PM +0000, Jonathan Wakely wrote:
>> On 08/01/16 19:18 +0000, Jonathan Wakely wrote:
>> >This resolves the longstanding issue that #include <math.h> uses the C
>> >library header, which on most targets doesn't declare the additional
>> >overloads required by C++11 26.8 [c.math], and similarly for
>> ><stdlib.h>.
>> >
>> >With this patch libstdc++ provides its own <math.h> and <stdlib.h>
>> >wrappers, which are equivalent to <cmath> or <cstdlib> followed by
>> >using-directives for all standard names. This means there are no more
>> >inconsistencies in the contents of the <cxxx> and <xxx.h> headers.
>>
>> Tested x86_64-linux, powerpc64le-linux, powerpc-aix,
>> x86_64-freebsd10.2, x86_64-dragonfly4.2
>>
>> Committed to trunk.
>
>I think this fix is incomplete.  There are still some test errors
>because of missing signatures in the Plumhall testsuite.  Please
>check the information I've added to
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60401

This should fix it, tested powerpc64le-linux and committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 4490 bytes --]

commit a2d2a215d6ce58e9a2d6d9b5c3cded3c06b7cf8e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jan 20 16:47:57 2016 +0000

    Add C++11 <cmath> overloads to the global namespace
    
    	PR libstdc++/60401
    	* include/c_compatibility/math.h (acosh, asinh, atanh, acbrt,
    	copysign, erf, erfc, exp2, expm1, fdim, fma, fmax, fmin, hypot, ilogb,
    	lgamma, llrint, llround, log1p, log2, logb, lrint, lround, nearbyint,
    	nextafter, nexttoward, remainder, remquo, rint, round, scalbln, scalbn,
    	tgamma, trunc) [__cplusplus >= 201103L && _GLIBCXX_USE_C99_MATH_TR1]:
    	Add using declarations.
    	* testsuite/26_numerics/headers/cmath/60401.cc: New.

diff --git a/libstdc++-v3/include/c_compatibility/math.h b/libstdc++-v3/include/c_compatibility/math.h
index 67f5ef1..d1fe75d 100644
--- a/libstdc++-v3/include/c_compatibility/math.h
+++ b/libstdc++-v3/include/c_compatibility/math.h
@@ -74,5 +74,42 @@ using std::islessgreater;
 using std::isunordered;
 #endif
 
+#if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_MATH_TR1)
+using std::acosh;
+using std::asinh;
+using std::atanh;
+using std::cbrt;
+using std::copysign;
+using std::erf;
+using std::erfc;
+using std::exp2;
+using std::expm1;
+using std::fdim;
+using std::fma;
+using std::fmax;
+using std::fmin;
+using std::hypot;
+using std::ilogb;
+using std::lgamma;
+using std::llrint;
+using std::llround;
+using std::log1p;
+using std::log2;
+using std::logb;
+using std::lrint;
+using std::lround;
+using std::nearbyint;
+using std::nextafter;
+using std::nexttoward;
+using std::remainder;
+using std::remquo;
+using std::rint;
+using std::round;
+using std::scalbln;
+using std::scalbn;
+using std::tgamma;
+using std::trunc;
+#endif // C++11 && _GLIBCXX_USE_C99_MATH_TR1
+
 #endif
 #endif
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/60401.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/60401.cc
new file mode 100644
index 0000000..a6be94a
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/60401.cc
@@ -0,0 +1,68 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+
+// PR libstdc++/60401
+
+#include <math.h>
+
+namespace test
+{
+  template<typename T>
+    using F = T*;
+
+  F<float(float)>abs = ::abs;
+
+#ifdef _GLIBCXX_USE_C99_MATH_TR1
+  F<float(float)>		acosh		= ::acosh;
+  F<float(float)>		asinh		= ::asinh;
+  F<float(float)>		atanh		= ::atanh;
+  F<float(float)>		cbrt		= ::cbrt;
+  F<float(float, float)>	copysign	= ::copysign;
+  F<float(float)>		erf		= ::erf;
+  F<float(float)>		erfc		= ::erfc;
+  F<float(float)>		exp2		= ::exp2;
+  F<float(float)>		expm1		= ::expm1;
+  F<float(float, float)>	fdim		= ::fdim;
+  F<float(float, float, float)>	fma		= ::fma;
+  F<float(float, float)>	fmax		= ::fmax;
+  F<float(float, float)>	fmin		= ::fmin;
+  F<float(float, float)>	hypot		= ::hypot;
+  F<int(float)>			ilogb		= ::ilogb;
+  F<float(float)>		lgamma		= ::lgamma;
+  F<long long(float)>		llrint		= ::llrint;
+  F<long long(float)>		llround		= ::llround;
+  F<float(float)>		log1p		= ::log1p;
+  F<float(float)>		log2		= ::log2;
+  F<float(float)>		logb		= ::logb;
+  F<long(float)>		lrint		= ::lrint;
+  F<long(float)>		lround		= ::lround;
+  F<float(float)>		nearbyint	= ::nearbyint;
+  F<float(float, float)>	nextafter	= ::nextafter;
+  F<float(float, long double)>	nexttoward	= ::nexttoward;
+  F<float(float, float)>	remainder	= ::remainder;
+  F<float(float, float, int*)>	remquo		= ::remquo;
+  F<float(float)>		rint		= ::rint;
+  F<float(float)>		round		= ::round;
+  F<float(float, long)>		scalbln		= ::scalbln;
+  F<float(float, int)>		scalbn		= ::scalbn;
+  F<float(float)>		tgamma		= ::tgamma;
+  F<float(float)>		trunc		= ::trunc;
+#endif
+}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib
  2016-01-20 12:34   ` [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib Jonathan Wakely
@ 2016-01-21 13:39     ` Jonathan Wakely
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2016-01-21 13:39 UTC (permalink / raw)
  To: libstdc++, gcc-patches

On 20/01/16 12:34 +0000, Jonathan Wakely wrote:
>--- a/libstdc++-v3/include/c_global/ccomplex
>+++ b/libstdc++-v3/include/c_global/ccomplex
>@@ -35,6 +35,8 @@
> # include <bits/c++0x_warning.h>
> #endif
> 
>+extern "C++" {
> #include <complex>
>+}

P.S. I would have preferred not to do this around <complex> and add
the linkage specification inside <complex>, but that would also mean
adding it inside <sstream>, which includes the entire iostream
hierarchy and <string> and bits/stl_algobase.h and lots of other
headers. Maybe I'll clean that up in stage 1 but it's a big patch.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib
  2016-01-21  9:27 [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib Dominique d'Humières
@ 2016-01-21 13:36 ` Jonathan Wakely
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Wakely @ 2016-01-21 13:36 UTC (permalink / raw)
  To: Dominique d'Humières; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 810 bytes --]

On 21/01/16 10:27 +0100, Dominique d'Humières wrote:
>Jonathan,
>>     PR libstdc++/69386
>>     * include/c_global/ccomplex: Ensure C++ language linkage.
>>     * include/c_global/cmath: Likewise.
>>     * include/c_global/cstdlib: Likewise.
>>     * include/c_global/ctgmath: Likewise.
>>     * testsuite/17_intro/headers/c++2011/linkage.cc: New.
>
>The test  testsuite/17_intro/headers/c++2011/linkage.cc fails on darwin
>
>/opt/gcc/work/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc:47:19: fatal error: uchar.h: No such file or directory

I should have been checking which headers are actually supported,
fixed like this. This also adds extern "C++" to some more headers, so
that the order of including <math.h> and <complex.h> doesn't matter.

Tested powerpc64le-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 5470 bytes --]

commit 77a9e07d731a90aceb17f6fded227003b1c9c510
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Jan 21 13:07:01 2016 +0000

    libstdc++/69406 Fix test to check for supported headers
    
    	PR libstdc++/69406
    	* include/bits/cpp_type_traits.h: Ensure C++ language linkage.
    	* include/ext/type_traits.h: Likewise.
    	* testsuite/17_intro/headers/c++2011/linkage.cc: Check autoconf macros
    	for presence of C headers.
    	* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Adjust
    	dg-error line number.
    	* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: Likewise.
    	* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Likewise.
    	* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: Likewise.

diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h
index 3b188d4..fff1e99 100644
--- a/libstdc++-v3/include/bits/cpp_type_traits.h
+++ b/libstdc++-v3/include/bits/cpp_type_traits.h
@@ -64,6 +64,8 @@
 // removed.
 //
 
+extern "C++" {
+
 namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -408,5 +410,6 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3)
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
+} // extern "C++"
 
 #endif //_CPP_TYPE_TRAITS_H
diff --git a/libstdc++-v3/include/ext/type_traits.h b/libstdc++-v3/include/ext/type_traits.h
index 0a4f425..dd27657 100644
--- a/libstdc++-v3/include/ext/type_traits.h
+++ b/libstdc++-v3/include/ext/type_traits.h
@@ -34,6 +34,8 @@
 #include <bits/c++config.h>
 #include <bits/cpp_type_traits.h>
 
+extern "C++" {
+
 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -214,5 +216,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace
+} // extern "C++"
 
 #endif 
diff --git a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
index 33e7053..67c384b 100644
--- a/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
+++ b/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc
@@ -20,15 +20,23 @@
 
 // libstdc++/69386
 
+#include <bits/c++config.h>
+
 extern "C"
 {
 #include <assert.h>
+#ifdef _GLIBCXX_HAVE_COMPLEX_H
 #include <complex.h>
+#endif
 #include <ctype.h>
 #include <errno.h>
+#ifdef _GLIBCXX_HAVE_FENV_H
 #include <fenv.h>
+#endif
 #include <float.h>
+#ifdef _GLIBCXX_HAVE_INTTYPES_H
 #include <inttypes.h>
+#endif
 #include <iso646.h>
 #include <limits.h>
 #include <locale.h>
@@ -36,15 +44,27 @@ extern "C"
 #include <setjmp.h>
 #include <signal.h>
 #include <stdarg.h>
+#ifdef _GLIBCXX_HAVE_STDBOOL_H
 #include <stdbool.h>
+#endif
 #include <stddef.h>
+#ifdef _GLIBCXX_HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef _GLIBCXX_HAVE_TGMATH_H
 #include <tgmath.h>
+#endif
 #include <time.h>
+#if __has_include(<uchar.h>)
 #include <uchar.h>
+#endif
+#ifdef _GLIBCXX_HAVE_WCHAR_H
 #include <wchar.h>
+#endif
+#ifdef _GLIBCXX_HAVE_WCTYPE_H
 #include <wctype.h>
+#endif
 }
diff --git a/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc
index f0c48d0..09d2c7c 100644
--- a/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc
+++ b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc
@@ -35,4 +35,4 @@ int main()
 }
 
 // { dg-error "required from" "" { target *-*-* } 28 }
-// { dg-error "no type" "" { target *-*-* } 69 } 
+// { dg-error "no type" "" { target *-*-* } 71 } 
diff --git a/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc
index cee08a3..567684e 100644
--- a/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc
+++ b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc
@@ -36,5 +36,5 @@ int main()
 }
 
 // { dg-error "invalid use of incomplete" "" { target *-*-* } 28 } 
-// { dg-error "declaration of" "" { target *-*-* } 98 }
-// { dg-error "declaration of" "" { target *-*-* } 101 }
+// { dg-error "declaration of" "" { target *-*-* } 100 }
+// { dg-error "declaration of" "" { target *-*-* } 103 }
diff --git a/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc
index 98ba8a6..c946a4f 100644
--- a/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc
+++ b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc
@@ -35,4 +35,4 @@ int main()
 }
 
 // { dg-error "required from" "" { target *-*-* } 28 }
-// { dg-error "no type" "" { target *-*-* } 112 }
+// { dg-error "no type" "" { target *-*-* } 114 }
diff --git a/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc
index 14e671d..a2cc4c7 100644
--- a/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc
+++ b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc
@@ -36,5 +36,5 @@ int main()
 }
 
 // { dg-error "invalid use of incomplete" "" { target *-*-* } 28 } 
-// { dg-error "declaration of" "" { target *-*-* } 141 }
-// { dg-error "declaration of" "" { target *-*-* } 144 }
+// { dg-error "declaration of" "" { target *-*-* } 143 }
+// { dg-error "declaration of" "" { target *-*-* } 146 }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib
@ 2016-01-21  9:27 Dominique d'Humières
  2016-01-21 13:36 ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: Dominique d'Humières @ 2016-01-21  9:27 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

Jonathan,
>     PR libstdc++/69386
>     * include/c_global/ccomplex: Ensure C++ language linkage.
>     * include/c_global/cmath: Likewise.
>     * include/c_global/cstdlib: Likewise.
>     * include/c_global/ctgmath: Likewise.
>     * testsuite/17_intro/headers/c++2011/linkage.cc: New.

The test  testsuite/17_intro/headers/c++2011/linkage.cc fails on darwin

/opt/gcc/work/libstdc++-v3/testsuite/17_intro/headers/c++2011/linkage.cc:47:19: fatal error: uchar.h: No such file or directory

TIA

Dominique

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-01-21 13:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-08 19:19 [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h Jonathan Wakely
2016-01-19 21:44 ` Jonathan Wakely
2016-01-20 12:34   ` [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib Jonathan Wakely
2016-01-21 13:39     ` Jonathan Wakely
2016-01-20 16:18   ` [patch] libstdc++/14608 Add C++-conforming wrappers for stdlib.h and math.h Dominik Vogt
2016-01-20 17:45     ` Jonathan Wakely
2016-01-21  9:27 [patch] libstdc++/69386 Ensure C++ language linkage in cmath and cstdlib Dominique d'Humières
2016-01-21 13:36 ` Jonathan Wakely

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).