diff mbox

complex.h

Message ID alpine.DEB.2.02.1207281628130.8721@laptop-mg.saclay.inria.fr
State New
Headers show

Commit Message

Marc Glisse July 28, 2012, 2:43 p.m. UTC
Hello,

here is a patch for PR54112. It does 2 things:
* #undef complex after including the system's complex.h
* in C++11, still include the system's complex.h

The C++11 standard says that including complex.h is equivalent to 
including <complex>, with the rationale that a C++ compiler can't parse a 
C99 complex.h header. However, g++, as an extension, handles _Complex, so 
it makes sense to also provide the prototypes for cacos and other C99 
complex math functions.

Tested, no regression.

(Cc: Benjamin, who wrote the header)

2012-07-28  Marc Glisse  <marc.glisse@inria.fr>

         PR libstdc++/54112
 	* include/c_compatibility/complex.h: Undefine complex, always
 	include system's complex.h if present.
 	* testsuite/26_numerics/complex/c99.cc: New testcase.
 	* testsuite/17_intro/headers/c++1998/complex.cc: Likewise.

Comments

Marc Glisse Aug. 10, 2012, 7:17 p.m. UTC | #1
Ping

http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01440.html

On Sat, 28 Jul 2012, Marc Glisse wrote:

> Hello,
>
> here is a patch for PR54112. It does 2 things:
> * #undef complex after including the system's complex.h
> * in C++11, still include the system's complex.h
>
> The C++11 standard says that including complex.h is equivalent to including 
> <complex>, with the rationale that a C++ compiler can't parse a C99 complex.h 
> header. However, g++, as an extension, handles _Complex, so it makes sense to 
> also provide the prototypes for cacos and other C99 complex math functions.
>
> Tested, no regression.
>
> (Cc: Benjamin, who wrote the header)
>
> 2012-07-28  Marc Glisse  <marc.glisse@inria.fr>
>
>        PR libstdc++/54112
> 	* include/c_compatibility/complex.h: Undefine complex, always
> 	include system's complex.h if present.
> 	* testsuite/26_numerics/complex/c99.cc: New testcase.
> 	* testsuite/17_intro/headers/c++1998/complex.cc: Likewise.
Jonathan Wakely Aug. 11, 2012, midnight UTC | #2
Let's CC Gaby, who likes to keep an eye on patches involving <complex>


On 10 August 2012 20:17, Marc Glisse wrote:
> Ping
>
> http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01440.html
>
>
> On Sat, 28 Jul 2012, Marc Glisse wrote:
>
>> Hello,
>>
>> here is a patch for PR54112. It does 2 things:
>> * #undef complex after including the system's complex.h
>> * in C++11, still include the system's complex.h
>>
>> The C++11 standard says that including complex.h is equivalent to
>> including <complex>, with the rationale that a C++ compiler can't parse a
>> C99 complex.h header. However, g++, as an extension, handles _Complex, so it
>> makes sense to also provide the prototypes for cacos and other C99 complex
>> math functions.
>>
>> Tested, no regression.
>>
>> (Cc: Benjamin, who wrote the header)
>>
>> 2012-07-28  Marc Glisse  <marc.glisse@inria.fr>
>>
>>        PR libstdc++/54112
>>         * include/c_compatibility/complex.h: Undefine complex, always
>>         include system's complex.h if present.
>>         * testsuite/26_numerics/complex/c99.cc: New testcase.
>>         * testsuite/17_intro/headers/c++1998/complex.cc: Likewise.
>
>
> --
> Marc Glisse
Paolo Carlini Aug. 11, 2012, 4:52 p.m. UTC | #3
On 08/10/2012 09:17 PM, Marc Glisse wrote:
> Ping
>
> http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01440.html
I would say, let's give Gaby and Benjamin another couple of days, then 
Marc is welcome to commit the patch. And, after all the help he gave us 
to sort out the Sparc issues vs c++11 we can only trust him about the 
header intricacies, eh! Thanks!

Paolo.
Marc Glisse Aug. 11, 2012, 5:05 p.m. UTC | #4
On Sat, 11 Aug 2012, Paolo Carlini wrote:

> On 08/10/2012 09:17 PM, Marc Glisse wrote:
>> Ping
>> 
>> http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01440.html
> I would say, let's give Gaby and Benjamin another couple of days, then Marc 
> is welcome to commit the patch. And, after all the help he gave us to sort 
> out the Sparc issues vs c++11 we can only trust him about the header 
> intricacies, eh! Thanks!

To be honest, I only checked the patch on linux/glibc, so there is a real 
risk on other platforms (which I don't have access to). I also did a quick 
sanity check on freebsd (not a true test).
Paolo Carlini Aug. 11, 2012, 6:59 p.m. UTC | #5
Marc Glisse <marc.glisse@inria.fr> ha scritto:

>To be honest, I only checked the patch on linux/glibc, so there is a
>real
>risk on other platforms (which I don't have access to). I also did a
>quick
>sanity check on freebsd (not a true test).

Ok, conditioning the small change on glibc would not be a big deal, in case. Let's ask Rainer to double check Solaris, anyway.

Paolo
Gabriel Dos Reis Aug. 13, 2012, 10:46 a.m. UTC | #6
On Fri, Aug 10, 2012 at 7:00 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> Let's CC Gaby, who likes to keep an eye on patches involving <complex>

Thanks Jonathan.

The patch is OK -- though I suspect we should have a documentation note
about the extension of allowing other C99 complex functions in <complex.h>.

-- Gaby

>
>
> On 10 August 2012 20:17, Marc Glisse wrote:
>> Ping
>>
>> http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01440.html
>>
>>
>> On Sat, 28 Jul 2012, Marc Glisse wrote:
>>
>>> Hello,
>>>
>>> here is a patch for PR54112. It does 2 things:
>>> * #undef complex after including the system's complex.h
>>> * in C++11, still include the system's complex.h
>>>
>>> The C++11 standard says that including complex.h is equivalent to
>>> including <complex>, with the rationale that a C++ compiler can't parse a
>>> C99 complex.h header. However, g++, as an extension, handles _Complex, so it
>>> makes sense to also provide the prototypes for cacos and other C99 complex
>>> math functions.
>>>
>>> Tested, no regression.
>>>
>>> (Cc: Benjamin, who wrote the header)
>>>
>>> 2012-07-28  Marc Glisse  <marc.glisse@inria.fr>
>>>
>>>        PR libstdc++/54112
>>>         * include/c_compatibility/complex.h: Undefine complex, always
>>>         include system's complex.h if present.
>>>         * testsuite/26_numerics/complex/c99.cc: New testcase.
>>>         * testsuite/17_intro/headers/c++1998/complex.cc: Likewise.
>>
>>
>> --
>> Marc Glisse
Marc Glisse Aug. 13, 2012, 11:17 a.m. UTC | #7
On Mon, 13 Aug 2012, Gabriel Dos Reis wrote:

> On Fri, Aug 10, 2012 at 7:00 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>> Let's CC Gaby, who likes to keep an eye on patches involving <complex>
>
> Thanks Jonathan.
>
> The patch is OK -- though I suspect we should have a documentation note
> about the extension of allowing other C99 complex functions in <complex.h>.

Thanks.

What about adding at the end of this page:
http://gcc.gnu.org/onlinedocs/libstdc++/manual/numerics.html#numerics.complex.processing

"As an extension to C++11 and for increased compatibility with C, 
<complex.h> includes both <complex> and the C99 <complex.h> (if the C 
library provides it)."

(there may be better places and better explanations...)
Gabriel Dos Reis Aug. 13, 2012, 11:35 a.m. UTC | #8
On Mon, Aug 13, 2012 at 6:17 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Mon, 13 Aug 2012, Gabriel Dos Reis wrote:
>
>> On Fri, Aug 10, 2012 at 7:00 PM, Jonathan Wakely <jwakely.gcc@gmail.com>
>> wrote:
>>>
>>> Let's CC Gaby, who likes to keep an eye on patches involving <complex>
>>
>>
>> Thanks Jonathan.
>>
>> The patch is OK -- though I suspect we should have a documentation note
>> about the extension of allowing other C99 complex functions in
>> <complex.h>.
>
>
> Thanks.
>
> What about adding at the end of this page:
> http://gcc.gnu.org/onlinedocs/libstdc++/manual/numerics.html#numerics.complex.processing
>
> "As an extension to C++11 and for increased compatibility with C,
> <complex.h> includes both <complex> and the C99 <complex.h> (if the C
> library provides it)."
>
> (there may be better places and better explanations...)
>
> --
> Marc Glisse

That is fine.

Thanks,

-- Gaby
Marc Glisse Aug. 13, 2012, 11:57 a.m. UTC | #9
On Mon, 13 Aug 2012, Gabriel Dos Reis wrote:

> On Mon, Aug 13, 2012 at 6:17 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
>> On Mon, 13 Aug 2012, Gabriel Dos Reis wrote:
>>
>>> On Fri, Aug 10, 2012 at 7:00 PM, Jonathan Wakely <jwakely.gcc@gmail.com>
>>> wrote:
>>>>
>>>> Let's CC Gaby, who likes to keep an eye on patches involving <complex>
>>>
>>>
>>> Thanks Jonathan.
>>>
>>> The patch is OK -- though I suspect we should have a documentation note
>>> about the extension of allowing other C99 complex functions in
>>> <complex.h>.
>>
>>
>> Thanks.
>>
>> What about adding at the end of this page:
>> http://gcc.gnu.org/onlinedocs/libstdc++/manual/numerics.html#numerics.complex.processing
>>
>> "As an extension to C++11 and for increased compatibility with C,
>> <complex.h> includes both <complex> and the C99 <complex.h> (if the C
>> library provides it)."
>>
>> (there may be better places and better explanations...)
>>
>> --
>> Marc Glisse
>
> That is fine.
>
> Thanks,

I only modified the xml version. I expect the html version will be updated 
the next time someone who knows what they are doing touches the doc...
Rainer Orth Aug. 13, 2012, 12:46 p.m. UTC | #10
Paolo Carlini <paolo.carlini@oracle.com> writes:

> Marc Glisse <marc.glisse@inria.fr> ha scritto:
>
>>To be honest, I only checked the patch on linux/glibc, so there is a
>>real 
>>risk on other platforms (which I don't have access to). I also did a
>>quick 
>>sanity check on freebsd (not a true test).
>
> Ok, conditioning the small change on glibc would not be a big deal, in
> case. Let's ask Rainer to double check Solaris, anyway.

The testcase from the PR fails on i386-pc-solaris2.11 with g++ 4.7.0,
but works with #undef complex added, for all of -std=c++98/03/11.  I
don't have an installed version of mainline, but will keep an eye for
failures during the next round of bootstraps.

	Rainer
Marc Glisse Aug. 13, 2012, 1:05 p.m. UTC | #11
On Mon, 13 Aug 2012, Rainer Orth wrote:

> Paolo Carlini <paolo.carlini@oracle.com> writes:
>
>> Marc Glisse <marc.glisse@inria.fr> ha scritto:
>>
>>> To be honest, I only checked the patch on linux/glibc, so there is a
>>> real
>>> risk on other platforms (which I don't have access to). I also did a
>>> quick
>>> sanity check on freebsd (not a true test).
>>
>> Ok, conditioning the small change on glibc would not be a big deal, in
>> case. Let's ask Rainer to double check Solaris, anyway.
>
> The testcase from the PR fails on i386-pc-solaris2.11 with g++ 4.7.0,
> but works with #undef complex added, for all of -std=c++98/03/11.

That should be fine then.

> I don't have an installed version of mainline, but will keep an eye for 
> failures during the next round of bootstraps.

Thank you,
Jonathan Wakely Aug. 13, 2012, 5:59 p.m. UTC | #12
On 13 August 2012 12:57, Marc Glisse wrote:
> I only modified the xml version. I expect the html version will be updated
> the next time someone who knows what they are doing touches the doc...

That's no problem, I tend to regenerate the html fairly frequently.

Thanks.
diff mbox

Patch

Index: libstdc++-v3/include/c_compatibility/complex.h
===================================================================
--- libstdc++-v3/include/c_compatibility/complex.h	(revision 189925)
+++ libstdc++-v3/include/c_compatibility/complex.h	(working copy)
@@ -23,20 +23,21 @@ 
 // <http://www.gnu.org/licenses/>.
 
 /** @file complex.h
  *  This is a Standard C++ Library header.
  */
 
 #include <bits/c++config.h>
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 # include <ccomplex>
-#else
-# if _GLIBCXX_HAVE_COMPLEX_H
-#  include_next <complex.h>
-# endif
+#endif
+
+#if _GLIBCXX_HAVE_COMPLEX_H
+# include_next <complex.h>
+# undef complex
 #endif
 
 #ifndef _GLIBCXX_COMPLEX_H
 #define _GLIBCXX_COMPLEX_H 1
 
 #endif
Index: libstdc++-v3/testsuite/26_numerics/complex/c99.cc
===================================================================
--- libstdc++-v3/testsuite/26_numerics/complex/c99.cc	(revision 0)
+++ libstdc++-v3/testsuite/26_numerics/complex/c99.cc	(revision 0)
@@ -0,0 +1,36 @@ 
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+// Copyright (C) 2012 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/>.
+
+// libstdc++/54112
+#include <bits/c++config.h>
+#if _GLIBCXX_HAVE_COMPLEX_H
+# include <complex.h>
+#endif
+
+int main()
+{
+  bool test __attribute__((unused)) = true;
+
+#if _GLIBCXX_HAVE_COMPLEX_H
+  double _Complex x = .5;
+  double _Complex y = cacos (x);
+  (void)y;
+#endif
+}

Property changes on: libstdc++-v3/testsuite/26_numerics/complex/c99.cc
___________________________________________________________________
Added: svn:eol-style
   + native
Added: svn:keywords
   + Author Date Id Revision URL

Index: libstdc++-v3/testsuite/17_intro/headers/c++1998/complex.cc
===================================================================
--- libstdc++-v3/testsuite/17_intro/headers/c++1998/complex.cc	(revision 0)
+++ libstdc++-v3/testsuite/17_intro/headers/c++1998/complex.cc	(revision 0)
@@ -0,0 +1,26 @@ 
+// { dg-do compile }
+
+// Copyright (C) 2012 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/>.
+
+// libstdc++/54112
+#include <bits/c++config.h>
+#if _GLIBCXX_HAVE_COMPLEX_H
+# include <complex.h>
+#endif
+#include <tr1/complex>
+std::complex<double> x;