From dae8f8199df9eae5909e641f9ccd1d73027bdefc Mon Sep 17 00:00:00 2001 From: Brooks Moses Date: Tue, 14 Apr 2015 03:49:38 +0000 Subject: Make libstdc++'s complex and complex.h modular. In C++11, this was already essentially the case. C++11 simply removes the C99 and does not make its facilities available. That is a fine and reasonable stance and I've preserved it. I've also removed the unconditional (and dead) undef that was breaking modular builds of the header. The question is what should and do in C++98. Currently these two headers conspire to undef 'complex' only when both are included. This doesn't actually work well as it relies on non-modular behavior of observing the order of inclusion. My proposed solution is to simply make including both and in the same file an error in C++98. This error remains non-modular, but is phrased in a way that should not preclude building this code with modules. In a modular build, the polite error simply won't trigger and instead the user will be faced with a compile error if they ever try to use 'complex' as something other than a macro expanding to '_Complex'. Eventually, we can use an explicit conflict marking in a modules map or other tool to surface this kind of error even to modules builds. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/google/gcc-4_9@222074 138bc75d-0d04-0410-961f-82ee72b054a4 --- .../aarch64-grtev4-linux-gnu.xfail | 4 ++++ .../powerpc64le-grtev4-linux-gnu.xfail | 4 ++++ .../x86_64-grtev4-linux-gnu.xfail | 4 ++++ libstdc++-v3/include/c_compatibility/complex.h | 28 ++++++++++++++-------- libstdc++-v3/include/std/complex | 10 ++++++-- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/contrib/testsuite-management/aarch64-grtev4-linux-gnu.xfail b/contrib/testsuite-management/aarch64-grtev4-linux-gnu.xfail index a2a027e5338..a459149ee01 100644 --- a/contrib/testsuite-management/aarch64-grtev4-linux-gnu.xfail +++ b/contrib/testsuite-management/aarch64-grtev4-linux-gnu.xfail @@ -18,6 +18,10 @@ FAIL: gcc.dg/wself-assign-1.c (test for warnings, line 20) FAIL: gcc.dg/wself-assign-1.c (test for warnings, line 21) FAIL: gcc.dg/wself-assign-1.c (test for warnings, line 22) +# Also xfailed in x86; Google b/20184248 +FAIL: 17_intro/headers/c++1998/complex.cc (test for excess errors) +FAIL: 26_numerics/complex/c99.cc (test for excess errors) + # AArch64-specific; appear to be missing "loop turned into non-loop; it never loops" output. FAIL: gcc.dg/unroll_1.c (test for warnings, line 14) FAIL: gcc.dg/unroll_1.c (test for warnings, line 24) diff --git a/contrib/testsuite-management/powerpc64le-grtev4-linux-gnu.xfail b/contrib/testsuite-management/powerpc64le-grtev4-linux-gnu.xfail index 410cdb94311..d8995e0cd1f 100644 --- a/contrib/testsuite-management/powerpc64le-grtev4-linux-gnu.xfail +++ b/contrib/testsuite-management/powerpc64le-grtev4-linux-gnu.xfail @@ -18,6 +18,10 @@ FAIL: gcc.dg/wself-assign-1.c (test for warnings, line 20) FAIL: gcc.dg/wself-assign-1.c (test for warnings, line 21) FAIL: gcc.dg/wself-assign-1.c (test for warnings, line 22) +# Also xfailed in x86; Google b/20184248 +FAIL: 17_intro/headers/c++1998/complex.cc (test for excess errors) +FAIL: 26_numerics/complex/c99.cc (test for excess errors) + # PPCle-specific. From PR33512, still failing in truck despite resolved PR. FAIL: gcc.dg/and-1.c scan-assembler-not nand diff --git a/contrib/testsuite-management/x86_64-grtev4-linux-gnu.xfail b/contrib/testsuite-management/x86_64-grtev4-linux-gnu.xfail index a6eb7eca038..b4fa6933791 100644 --- a/contrib/testsuite-management/x86_64-grtev4-linux-gnu.xfail +++ b/contrib/testsuite-management/x86_64-grtev4-linux-gnu.xfail @@ -21,6 +21,10 @@ FAIL: gcc.dg/wself-assign-1.c (test for warnings, line 22) # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60037 FAIL: ext/random/hypergeometric_distribution/operators/values.cc execution test +# Google b/20184248 +FAIL: 17_intro/headers/c++1998/complex.cc (test for excess errors) +FAIL: 26_numerics/complex/c99.cc (test for excess errors) + # Google b/14137212 FAIL: 29_atomics/atomic/cons/user_pod.cc (test for excess errors) diff --git a/libstdc++-v3/include/c_compatibility/complex.h b/libstdc++-v3/include/c_compatibility/complex.h index d072b68a835..b15361ea0d5 100644 --- a/libstdc++-v3/include/c_compatibility/complex.h +++ b/libstdc++-v3/include/c_compatibility/complex.h @@ -26,21 +26,29 @@ * This is a Standard C++ Library header. */ -#include +#ifndef _GLIBCXX_COMPLEX_H +#define _GLIBCXX_COMPLEX_H 1 #if __cplusplus >= 201103L # include +#else // C++98 and C++03 + +// The C++ header is incompatible with the C99 header, +// they cannot be included into a single translation unit portably. Notably, +// C++11's does not include C99's and in C++11's +// is defined to provide only what C++11's does in a +// different namespace. +#ifdef _GLIBCXX_COMPLEX +# error Cannot include both and C99's #endif -#if _GLIBCXX_HAVE_COMPLEX_H -# include_next -# ifdef _GLIBCXX_COMPLEX -// See PR56111, keep the macro in C++03 if possible. -# undef complex -# endif -#endif +// Delegate to a system complex.h if we don't provide it as part of the C++ +// implementation. +#include_next -#ifndef _GLIBCXX_COMPLEX_H -#define _GLIBCXX_COMPLEX_H 1 +// Provide a define indicating that a C99-style has been included. +#define _GLIBCXX_C99_COMPLEX_H + +#endif // C++98 and C++03 #endif diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex index 941e6b7d845..3104b584eb6 100644 --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -44,8 +44,14 @@ #include #include -// Get rid of a macro possibly defined in -#undef complex +// The C++ header is incompatible with the C99 header, +// they cannot be included into a single translation unit portably. Notably, +// C++11's does not include C99's and in C++11's +// is defined to provide only what C++11's does in a +// different namespace. +#ifdef _GLIBCXX_C99_COMPLEX_H +#error Cannot include both and C99's +#endif namespace std _GLIBCXX_VISIBILITY(default) { -- cgit v1.2.3