aboutsummaryrefslogtreecommitdiff
path: root/math
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-10-09 14:58:34 +0100
committerFlorian Weimer <fweimer@redhat.com>2017-10-09 16:18:11 +0200
commitd6c064e914cba3277d852c9fa27db53f0059ff8c (patch)
treee8ce891a1960979738c5a262475b7487b5881883 /math
parent645ac9aaf89e3311949828546df6334322f48933 (diff)
downloadglibc-d6c064e914cba3277d852c9fa27db53f0059ff8c.tar
glibc-d6c064e914cba3277d852c9fa27db53f0059ff8c.tar.gz
glibc-d6c064e914cba3277d852c9fa27db53f0059ff8c.tar.bz2
glibc-d6c064e914cba3277d852c9fa27db53f0059ff8c.zip
Ensure C99 and C11 interfaces are available for C++ [BZ #21326]
This patch ensures that the C99 and C11 features required by C++ are defined according to the value of the __cplusplus macro, and not just because G++ always defines _GNU_SOURCE. This will allow G++ to stop defining _GNU_SOURCE some day, without causing the C99 and C11 interfaces to disappear for C++ programs. [BZ #21326] * include/features.h [__cplusplus >= 201103] (__USE_ISOC99): Define. [__cplusplus >= 201703] (__USE_ISOCXX17, __USE_ISOC11): Define. * math/Makefile (test-math-cxx11): New test. * math/test-math-cxx11.cc: New file.
Diffstat (limited to 'math')
-rw-r--r--math/Makefile4
-rw-r--r--math/test-math-cxx11.cc160
2 files changed, 163 insertions, 1 deletions
diff --git a/math/Makefile b/math/Makefile
index 008eeb2d18..d4f9e6b6e9 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -209,7 +209,7 @@ tests-static += atest-exp atest-sincos atest-exp2
ifneq (,$(CXX))
tests += test-math-isinff test-math-iszero test-math-issignaling \
- test-math-iscanonical
+ test-math-iscanonical test-math-cxx11
endif
ifneq (no,$(PERL))
@@ -354,6 +354,8 @@ CFLAGS-test-signgam-ullong-init.c = -std=c99
CFLAGS-test-signgam-ullong-static.c = -std=c99
CFLAGS-test-signgam-ullong-init-static.c = -std=c99
+CFLAGS-test-math-cxx11.cc = -std=c++11
+
CFLAGS-test-math-isinff.cc = -std=gnu++11
CFLAGS-test-math-iszero.cc = -std=gnu++11
CFLAGS-test-math-issignaling.cc = -std=gnu++11
diff --git a/math/test-math-cxx11.cc b/math/test-math-cxx11.cc
new file mode 100644
index 0000000000..8417cdd6e3
--- /dev/null
+++ b/math/test-math-cxx11.cc
@@ -0,0 +1,160 @@
+/* Test C99 math functions are available in C++11 without _GNU_SOURCE.
+ Copyright (C) 2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#undef _GNU_SOURCE
+#undef _DEFAULT_SOURCE
+#undef _XOPEN_SOURCE
+#undef _POSIX_SOURCE
+#undef _POSIX_C_SOURCE
+// __STRICT_ANSI__ gets defined by -std=c++11 in CFLAGS
+#include <math.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+#ifdef _GNU_SOURCE
+ printf ("FAIL: _GNU_SOURCE is defined.\n");
+ return 1;
+#endif
+
+#if __cplusplus >= 201103L
+ /* Verify that C11 math functions and types are defined for C++11,
+ without _GNU_SOURCE being defined. [BZ #21326] */
+ (void) FP_INFINITE;
+ (void) FP_NAN;
+ (void) FP_NORMAL;
+ (void) FP_SUBNORMAL;
+ (void) FP_ZERO;
+ double_t d = 1.0;
+ (void) d;
+ float_t f = 1.0f;
+ (void) f;
+ (void) acosh;
+ (void) acoshf;
+ (void) acoshl;
+ (void) asinh;
+ (void) asinhf;
+ (void) asinhl;
+ (void) atanh;
+ (void) atanhf;
+ (void) atanhl;
+ (void) cbrt;
+ (void) cbrtf;
+ (void) cbrtl;
+ (void) copysign;
+ (void) copysignf;
+ (void) copysignl;
+ (void) erf;
+ (void) erff;
+ (void) erfl;
+ (void) erfc;
+ (void) erfcf;
+ (void) erfcl;
+ (void) exp2;
+ (void) exp2f;
+ (void) exp2l;
+ (void) expm1;
+ (void) expm1f;
+ (void) expm1l;
+ (void) fdim;
+ (void) fdimf;
+ (void) fdiml;
+ (void) fma;
+ (void) fmaf;
+ (void) fmal;
+ (void) fmax;
+ (void) fmaxf;
+ (void) fmaxl;
+ (void) fmin;
+ (void) fminf;
+ (void) fminl;
+ (void) hypot;
+ (void) hypotf;
+ (void) hypotl;
+ (void) ilogb;
+ (void) ilogbf;
+ (void) ilogbl;
+ (void) lgamma;
+ (void) lgammaf;
+ (void) lgammal;
+ (void) llrint;
+ (void) llrintf;
+ (void) llrintl;
+ (void) llround;
+ (void) llroundf;
+ (void) llroundl;
+ (void) log1p;
+ (void) log1pf;
+ (void) log1pl;
+ (void) log2;
+ (void) log2f;
+ (void) log2l;
+ (void) logb;
+ (void) logbf;
+ (void) logbl;
+ (void) lrint;
+ (void) lrintf;
+ (void) lrintl;
+ (void) lround;
+ (void) lroundf;
+ (void) lroundl;
+ (void) nan;
+ (void) nanf;
+ (void) nanl;
+ (void) nearbyint;
+ (void) nearbyintf;
+ (void) nearbyintl;
+ (void) nextafter;
+ (void) nextafterf;
+ (void) nextafterl;
+ (void) nexttoward;
+ (void) nexttowardf;
+ (void) nexttowardl;
+ (void) remainder;
+ (void) remainderf;
+ (void) remainderl;
+ (void) remquo;
+ (void) remquof;
+ (void) remquol;
+ (void) rint;
+ (void) rintf;
+ (void) rintl;
+ (void) round;
+ (void) roundf;
+ (void) roundl;
+ (void) scalbln;
+ (void) scalblnf;
+ (void) scalblnl;
+ (void) scalbn;
+ (void) scalbnf;
+ (void) scalbnl;
+ (void) tgamma;
+ (void) tgammaf;
+ (void) tgammal;
+ (void) trunc;
+ (void) truncf;
+ (void) truncl;
+ printf ("PASS: C11 math functions present in C++11 without _GNU_SOURCE.\n");
+#else
+ printf ("UNSUPPORTED: C++11 not enabled.\n");
+#endif
+ return 0;
+}
+
+#include <support/test-driver.c>