Re: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2021-02-04 Thread Ed Smith-Rowland via Gcc-patches

On 2/4/21 6:31 AM, Tam S. B. wrote:

`__cpp_size_t_suffix` is defined as 202006L, but the draft standard says 
202011L: http://eel.is/c++draft/cpp.predefined#tab:cpp.predefined.ft-row-48


I looks like you're right. Both the latest draft and 
https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations 
agree. Not sure what's up with all the dates in the latest draft of P0330...


Jason, is this OK?

Ed


diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 48dec21d4b4..9f993c4aff2 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1028,7 +1028,7 @@ c_cpp_builtins (cpp_reader *pfile)
   if (cxx_dialect > cxx20)
{
  /* Set feature test macros for C++23.  */
- cpp_define (pfile, "__cpp_size_t_suffix=202006L");
+ cpp_define (pfile, "__cpp_size_t_suffix=202011L");
}
   if (flag_concepts)
 {
diff --git a/gcc/testsuite/g++.dg/cpp23/feat-cxx2b.C 
b/gcc/testsuite/g++.dg/cpp23/feat-cxx2b.C
index 94e08a4896c..4a342e967f8 100644
--- a/gcc/testsuite/g++.dg/cpp23/feat-cxx2b.C
+++ b/gcc/testsuite/g++.dg/cpp23/feat-cxx2b.C
@@ -544,6 +544,6 @@
 
 #ifndef __cpp_size_t_suffix
 #  error "__cpp_size_t_suffix"
-#elif __cpp_size_t_suffix != 202006
-#  error "__cpp_size_t_suffix != 202006"
+#elif __cpp_size_t_suffix != 202011
+#  error "__cpp_size_t_suffix != 202011"
 #endif


[wwwdocs] Mention C++23 flags and addition of size_t literals.

2021-02-03 Thread Ed Smith-Rowland via Gcc-patches

I pushed this patch to update changes to mention the C++23 flags and the size_t 
literals.

Ed

commit bfc68f3f88406a07757d111a0f894426a6bc4522
Author: Ed Smith-Rowland <3dw...@verizon.net  <mailto:3dw...@verizon.net>>
Date:   Wed Feb 3 14:23:00 2021 -0500

Mention C++23 flags and P0330R8, Literal Suffix for (signed) size_t.
Tweak an href in cxx-status.

diff --git a/htdocs/gcc-11/changes.html b/htdocs/gcc-11/changes.html
index efbf3341..a8b036c3 100644
--- a/htdocs/gcc-11/changes.html
+++ b/htdocs/gcc-11/changes.html
@@ -251,6 +251,18 @@ a work-in-progress.
   to C++ 20 Status
 
   
+  
+The C++ front end has experimental support for some of the upcoming C++23
+draft features with the -std=c++23, -std=gnu++23,
+-std=c++2b or -std=gnu++2b flags,
+including
+
+  P0330R8, Literal Suffix for (signed) size_t.
+
+For a full list of new features,
+see the C++
+status page.
+  
   Several C++ Defect Reports have been resolved, e.g.:
 
   DR 625, Use of auto as a template-argument
diff --git a/htdocs/projects/cxx-status.html b/htdocs/projects/cxx-status.html
index 91916930..94f45def 100644
--- a/htdocs/projects/cxx-status.html
+++ b/htdocs/projects/cxx-status.html
@@ -19,7 +19,7 @@
 C++14
 C++17
 C++20
-C++23
+C++23
 Technical Specifications
   
   


---

Summary of changes:
 htdocs/gcc-11/changes.html  | 12 
 htdocs/projects/cxx-status.html |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)



Re: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2021-02-01 Thread Ed Smith-Rowland via Gcc-patches

On 2/2/21 12:12 AM, Jason Merrill wrote:

On 2/1/21 9:15 PM, Ed Smith-Rowland wrote:

On 2/1/21 2:23 PM, Jakub Jelinek wrote:

On Mon, Feb 01, 2021 at 01:46:13PM -0500, Ed Smith-Rowland wrote:

@@ -0,0 +1,8 @@
+// { dg-do compile { target c++23 } }
+
+#include 
+#include 
+
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);
Shouldn't this be std::make_signed::type instead of 
std::ptrdiff_t
Yes it should. The paper goes on about ptrdiff_t but at the very end 
they punt on that in favor of what you have.


+std::ptrdiff_t pd1 = 1234z; // { dg-warning "use of C\+\+23 
ptrdiff_t integer constant" "" { target c++20_down } }
+std::ptrdiff_t PD1 = 5678Z; // { dg-warning "use of C\+\+23 
ptrdiff_t integer constant" "" { target c++20_down } }

Ditto here.

Agree.


+  const char *message = (result & CPP_N_UNSIGNED) == 
CPP_N_UNSIGNED

+    ? N_("use of C++23 size_t integer constant")
+    : N_("use of C++23 ptrdiff_t integer constant");

And here too (perhaps %::type%> )?
And maybe % too.

Agree.



--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -500,6 +500,9 @@ struct cpp_options
    /* Nonzero means tokenize C++20 module directives.  */
    unsigned char module_directives;
+  /* Nonzero for C++23 ptrdiff_t and size_t literals.  */

And drop "ptrdiff_t and " here?

+#define CPP_N_SIZE_T    0x200 /* C++23 size_t or ptrdiff_t 
literal  */

And " or ptrdiff_t" here?

While ptrdiff_t will usually be the same type, seems there is e.g.:
config/darwin.h:#define SIZE_TYPE "long unsigned int"
config/darwin.h:#define PTRDIFF_TYPE "int"
config/i386/djgpp.h:#define SIZE_TYPE "long unsigned int"
config/i386/djgpp.h:#define PTRDIFF_TYPE "int"
config/m32c/m32c.h:#define PTRDIFF_TYPE (TARGET_A16 ? "int" : "long 
int")

config/m32c/m32c.h:#define SIZE_TYPE "unsigned int"
config/rs6000/rs6000.h:#define PTRDIFF_TYPE "int"
config/rs6000/rs6000.h:#define SIZE_TYPE "long unsigned int"
config/s390/linux.h:#define SIZE_TYPE "long unsigned int"
config/s390/linux.h:#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" 
: "int")

config/visium/visium.h:#define SIZE_TYPE "unsigned int"
config/visium/visium.h:#define PTRDIFF_TYPE "long int"
config/vms/vms.h:#define SIZE_TYPE  "unsigned int"
config/vms/vms.h:#define PTRDIFF_TYPE (flag_vms_pointer_size == 
VMS_POINTER_SIZE_NONE ? \

config/vms/vms.h-  "int" : "long long int")
so quite a few differences.

Jakub


Here is my last patch with all the concerns addressed.

I am not smart enough to get the dg-warning regex in 
Wsize_t-literals.C to work. If someone could carry this over the 
finish line that would be great. Or give me pointers. I can't any more.


Your regex will work fine if you wrap it in {} instead of "", e.g.

{ dg-warning {use of C\+\+23 .size_t. integer constant} }

Jason


Thank you Jason,

So here is the latest in testing.

Ed


diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index dca6815a876..48dec21d4b4 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1025,6 +1025,11 @@ c_cpp_builtins (cpp_reader *pfile)
  cpp_define (pfile, "__cpp_aggregate_paren_init=201902L");
  cpp_define (pfile, "__cpp_using_enum=201907L");
}
+  if (cxx_dialect > cxx20)
+   {
+ /* Set feature test macros for C++23.  */
+ cpp_define (pfile, "__cpp_size_t_suffix=202006L");
+   }
   if (flag_concepts)
 {
  if (cxx_dialect >= cxx20)
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index fe40a0f728b..6374b72ed2d 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -834,6 +834,14 @@ interpret_integer (const cpp_token *token, unsigned int 
flags,
 type = ((flags & CPP_N_UNSIGNED)
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
+  else if (flags & CPP_N_SIZE_T)
+{
+  /* itk refers to fundamental types not aliased size types.  */
+  if (flags & CPP_N_UNSIGNED)
+   type = size_type_node;
+  else
+   type = signed_size_type_node;
+}
   else
 {
   type = integer_types[itk];
diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C 
b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
index f8d84ed..a30ec0f4f7e 100644
--- a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
+++ b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
@@ -17,6 +17,30 @@ unsigned long long int
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "

Re: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2021-02-01 Thread Ed Smith-Rowland via Gcc-patches

On 2/1/21 2:23 PM, Jakub Jelinek wrote:

On Mon, Feb 01, 2021 at 01:46:13PM -0500, Ed Smith-Rowland wrote:

@@ -0,0 +1,8 @@
+// { dg-do compile { target c++23 } }
+
+#include 
+#include 
+
+static_assert(std::is_same_v);
+static_assert(std::is_same_v);

Shouldn't this be std::make_signed::type instead of std::ptrdiff_t
Yes it should. The paper goes on about ptrdiff_t but at the very end 
they punt on that in favor of what you have.



+std::ptrdiff_t pd1 = 1234z; // { dg-warning "use of C\+\+23 ptrdiff_t integer constant" 
"" { target c++20_down } }
+std::ptrdiff_t PD1 = 5678Z; // { dg-warning "use of C\+\+23 ptrdiff_t integer constant" 
"" { target c++20_down } }

Ditto here.

Agree.



+ const char *message = (result & CPP_N_UNSIGNED) == CPP_N_UNSIGNED
+   ? N_("use of C++23 size_t integer constant")
+   : N_("use of C++23 ptrdiff_t integer constant");

And here too (perhaps %::type%> )?
And maybe % too.

Agree.



--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -500,6 +500,9 @@ struct cpp_options
/* Nonzero means tokenize C++20 module directives.  */
unsigned char module_directives;
  
+  /* Nonzero for C++23 ptrdiff_t and size_t literals.  */

And drop "ptrdiff_t and " here?


+#define CPP_N_SIZE_T   0x200 /* C++23 size_t or ptrdiff_t literal  */

And " or ptrdiff_t" here?

While ptrdiff_t will usually be the same type, seems there is e.g.:
config/darwin.h:#define SIZE_TYPE "long unsigned int"
config/darwin.h:#define PTRDIFF_TYPE "int"
config/i386/djgpp.h:#define SIZE_TYPE "long unsigned int"
config/i386/djgpp.h:#define PTRDIFF_TYPE "int"
config/m32c/m32c.h:#define PTRDIFF_TYPE (TARGET_A16 ? "int" : "long int")
config/m32c/m32c.h:#define SIZE_TYPE "unsigned int"
config/rs6000/rs6000.h:#define PTRDIFF_TYPE "int"
config/rs6000/rs6000.h:#define SIZE_TYPE "long unsigned int"
config/s390/linux.h:#define SIZE_TYPE "long unsigned int"
config/s390/linux.h:#define PTRDIFF_TYPE (TARGET_64BIT ? "long int" : "int")
config/visium/visium.h:#define SIZE_TYPE "unsigned int"
config/visium/visium.h:#define PTRDIFF_TYPE "long int"
config/vms/vms.h:#define SIZE_TYPE  "unsigned int"
config/vms/vms.h:#define PTRDIFF_TYPE (flag_vms_pointer_size == 
VMS_POINTER_SIZE_NONE ? \
config/vms/vms.h-  "int" : "long long int")
so quite a few differences.

Jakub


Here is my last patch with all the concerns addressed.

I am not smart enough to get the dg-warning regex in Wsize_t-literals.C 
to work. If someone could carry this over the finish line that would be 
great. Or give me pointers. I can't any more.


Ed


diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index dca6815a876..48dec21d4b4 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1025,6 +1025,11 @@ c_cpp_builtins (cpp_reader *pfile)
  cpp_define (pfile, "__cpp_aggregate_paren_init=201902L");
  cpp_define (pfile, "__cpp_using_enum=201907L");
}
+  if (cxx_dialect > cxx20)
+   {
+ /* Set feature test macros for C++23.  */
+ cpp_define (pfile, "__cpp_size_t_suffix=202006L");
+   }
   if (flag_concepts)
 {
  if (cxx_dialect >= cxx20)
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index fe40a0f728b..6374b72ed2d 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -834,6 +834,14 @@ interpret_integer (const cpp_token *token, unsigned int 
flags,
 type = ((flags & CPP_N_UNSIGNED)
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
+  else if (flags & CPP_N_SIZE_T)
+{
+  /* itk refers to fundamental types not aliased size types.  */
+  if (flags & CPP_N_UNSIGNED)
+   type = size_type_node;
+  else
+   type = signed_size_type_node;
+}
   else
 {
   type = integer_types[itk];
diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C 
b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
index f8d84ed..a30ec0f4f7e 100644
--- a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
+++ b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
@@ -17,6 +17,30 @@ unsigned long long int
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" uz(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long l

Re: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2021-02-01 Thread Ed Smith-Rowland via Gcc-patches

On 2/1/21 10:33 AM, Jason Merrill wrote:

On 1/30/21 6:22 PM, Ed Smith-Rowland wrote:

On 1/27/21 3:32 PM, Jakub Jelinek wrote:

On Sun, Oct 21, 2018 at 04:39:30PM -0400, Ed Smith-Rowland wrote:
This patch implements C++2a proposal P0330R2 Literal Suffixes for 
ptrdiff_t
and size_t*.  It's not official yet but looks very likely to pass.  
It is
incomplete because I'm looking for some opinions. 9We also might 
wait 'till

it actually passes).

This paper takes the direction of a language change rather than a 
library
change through C++11 literal operators.  This was after feedback on 
that

paper after a few iterations.

As coded in this patch, integer suffixes involving 'z' are errors 
in C and

warnings for C++ <= 17 (in addition to the usual warning about
implementation suffixes shadowing user-defined ones).

OTOH, the 'z' suffix is not currently legal - it can't break
currently-correct code in any C/C++ dialect.  furthermore, I 
suspect the
language direction was chosen to accommodate a similar addition to 
C20.


I'm thinking of making this feature available as an extension to 
all of

C/C++ perhaps with appropriate pedwarn.
GCC now supports -std=c++2b and -std=gnu++2b, are you going to 
update your

patch against it (and change for z/Z standing for ssize_t rather than
ptrdiff_t), plus incorporate the feedback from Joseph and Jason?

Jakub


Here is a rebased patch that is a bit leaner than the original.

Since I chose to be conservative in applying this just to C++23 I'm 
not adding this to C or t earlier versions of C++ as extensions. We 
can add that if people really want, maybe in stage 1.


The compat warning for C++ < 23 is not optional. since the suffixes 
are not preceded by '-' I don't hav much sympathy if people tried to 
make a literal 'z' operator. Which is the only reason I can see for a 
warning suppression.



+  /* itk refers to fundamental types not aliased size types.  */
+  if (flags & CPP_N_UNSIGNED)
+    type = size_type_node;
+  else
+    type = ptrdiff_type_node;


I thought size_type_node and ptrdiff_type_node were sort of fundamental 
the the others derived:


ssize_t:
  signed_size_type_node = c_common_signed_type (size_type_node);
???:
  unsigned_ptrdiff_type_node = c_common_unsigned_type (ptrdiff_type_node);

But I see in tree.c that things can be... interesting.

Fixed...

This is wrong if ptrdiff_t is a different size from size_t; it should 
be c_common_signed_type (size_type_node).



+  | (z ? (CPP_N_SIZE_T | CPP_N_LARGE) : 0));


Why CPP_N_LARGE here?  That would seem to suggest that size_t is 
always the same size as unsigned long long.



This doesn't need to be there. I don't use it anywhere.

Jason


Is this Ok if it passes testing on x86_64-linux?

Ed


diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index dca6815a876..48dec21d4b4 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1025,6 +1025,11 @@ c_cpp_builtins (cpp_reader *pfile)
  cpp_define (pfile, "__cpp_aggregate_paren_init=201902L");
  cpp_define (pfile, "__cpp_using_enum=201907L");
}
+  if (cxx_dialect > cxx20)
+   {
+ /* Set feature test macros for C++23.  */
+ cpp_define (pfile, "__cpp_size_t_suffix=202006L");
+   }
   if (flag_concepts)
 {
  if (cxx_dialect >= cxx20)
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index fe40a0f728b..bc4f6f9dfa7 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -834,6 +834,14 @@ interpret_integer (const cpp_token *token, unsigned int 
flags,
 type = ((flags & CPP_N_UNSIGNED)
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
+  else if (flags & CPP_N_SIZE_T)
+{
+  /* itk refers to fundamental types not aliased size types.  */
+  if (flags & CPP_N_UNSIGNED)
+   type = size_type_node;
+  else
+   type = c_common_signed_type (size_type_node);
+}
   else
 {
   type = integer_types[itk];
diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C 
b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
index f8d84ed..a30ec0f4f7e 100644
--- a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
+++ b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
@@ -17,6 +17,30 @@ unsigned long long int
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" uz(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" zu(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by

Re: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2021-01-30 Thread Ed Smith-Rowland via Gcc-patches

On 1/27/21 3:32 PM, Jakub Jelinek wrote:

On Sun, Oct 21, 2018 at 04:39:30PM -0400, Ed Smith-Rowland wrote:

This patch implements C++2a proposal P0330R2 Literal Suffixes for ptrdiff_t
and size_t*.  It's not official yet but looks very likely to pass.  It is
incomplete because I'm looking for some opinions. 9We also might wait 'till
it actually passes).

This paper takes the direction of a language change rather than a library
change through C++11 literal operators.  This was after feedback on that
paper after a few iterations.

As coded in this patch, integer suffixes involving 'z' are errors in C and
warnings for C++ <= 17 (in addition to the usual warning about
implementation suffixes shadowing user-defined ones).

OTOH, the 'z' suffix is not currently legal - it can't break
currently-correct code in any C/C++ dialect.  furthermore, I suspect the
language direction was chosen to accommodate a similar addition to C20.

I'm thinking of making this feature available as an extension to all of
C/C++ perhaps with appropriate pedwarn.

GCC now supports -std=c++2b and -std=gnu++2b, are you going to update your
patch against it (and change for z/Z standing for ssize_t rather than
ptrdiff_t), plus incorporate the feedback from Joseph and Jason?

Jakub


Here is a rebased patch that is a bit leaner than the original.

Since I chose to be conservative in applying this just to C++23 I'm not 
adding this to C or t earlier versions of C++ as extensions. We can add 
that if people really want, maybe in stage 1.


The compat warning for C++ < 23 is not optional. since the suffixes are 
not preceded by '-' I don't hav much sympathy if people tried to make a 
literal 'z' operator. Which is the only reason I can see for a warning 
suppression.


Built and tested on x86_64.

Ok?


diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index dca6815a876..48dec21d4b4 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -1025,6 +1025,11 @@ c_cpp_builtins (cpp_reader *pfile)
  cpp_define (pfile, "__cpp_aggregate_paren_init=201902L");
  cpp_define (pfile, "__cpp_using_enum=201907L");
}
+  if (cxx_dialect > cxx20)
+   {
+ /* Set feature test macros for C++23.  */
+ cpp_define (pfile, "__cpp_size_t_suffix=202006L");
+   }
   if (flag_concepts)
 {
  if (cxx_dialect >= cxx20)
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index fe40a0f728b..02e397bb0c0 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -834,6 +834,14 @@ interpret_integer (const cpp_token *token, unsigned int 
flags,
 type = ((flags & CPP_N_UNSIGNED)
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
+  else if (flags & CPP_N_SIZE_T)
+{
+  /* itk refers to fundamental types not aliased size types.  */
+  if (flags & CPP_N_UNSIGNED)
+   type = size_type_node;
+  else
+   type = ptrdiff_type_node;
+}
   else
 {
   type = integer_types[itk];
diff --git a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C 
b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
index f8d84ed..a30ec0f4f7e 100644
--- a/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
+++ b/gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
@@ -17,6 +17,30 @@ unsigned long long int
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" uz(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" zu(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" Z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" UZ(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" ZU(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
 //  Namespaces are no hiding place.
 namespace Long
 {
@@ -37,13 +61,50 @@ unsigned long long int
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator&quo

Re: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2021-01-27 Thread Ed Smith-Rowland via Gcc-patches

On 1/27/21 3:32 PM, Jakub Jelinek wrote:

On Sun, Oct 21, 2018 at 04:39:30PM -0400, Ed Smith-Rowland wrote:

This patch implements C++2a proposal P0330R2 Literal Suffixes for ptrdiff_t
and size_t*.  It's not official yet but looks very likely to pass.  It is
incomplete because I'm looking for some opinions. 9We also might wait 'till
it actually passes).

This paper takes the direction of a language change rather than a library
change through C++11 literal operators.  This was after feedback on that
paper after a few iterations.

As coded in this patch, integer suffixes involving 'z' are errors in C and
warnings for C++ <= 17 (in addition to the usual warning about
implementation suffixes shadowing user-defined ones).

OTOH, the 'z' suffix is not currently legal - it can't break
currently-correct code in any C/C++ dialect.  furthermore, I suspect the
language direction was chosen to accommodate a similar addition to C20.

I'm thinking of making this feature available as an extension to all of
C/C++ perhaps with appropriate pedwarn.

GCC now supports -std=c++2b and -std=gnu++2b, are you going to update your
patch against it (and change for z/Z standing for ssize_t rather than
ptrdiff_t), plus incorporate the feedback from Joseph and Jason?

Jakub


I'm actually working on it now!




Re: [RFC] Remove include/precompiled/expc++.h

2020-10-16 Thread Ed Smith-Rowland via Gcc-patches

On 10/15/20 7:21 PM, Jonathan Wakely wrote:

Ed,

In commit r232377 (aka 2be75957b80b640c0aac4356ab861edd0c2f1b9d in the
git repo) you added a new header to the include/precompiled directory.
That wasn't mentioned in the ChangeLog, wasn't in the patch posted to
https://gcc.gnu.org/legacy-ml/libstdc++/2016-01/msg00016.html and
wasn't added to include/Makefile.am, which means it never gets
precompiled, and never gets installed.

I don't think it was meant to be committed, so I think we should
remove it. Any objection?

We *could* add it to the build so it gets installed ... but meh.


Jonathan,

Go ahead and remove that header. Sorry for the noise.

Ed




Fwd: [PATCH,libstdc++] C++ constexpr tuple is broken.

2019-11-16 Thread Ed Smith-Rowland via gcc-patches

I missed a file in my recent patch for C++20 constexpr tuple. Bestrafe Mich.

Ed


2019-11-16  Edward Smith-Rowland  <3dw...@verizon.net>

	Repair the  part of C++20 p1032 Misc constexpr bits.
	* include/bits/uses_allocator.h (__uses_alloc0::_Sink::operaror=)
	(__use_alloc(const _Alloc&)) : Constexpr.


Index: include/bits/uses_allocator.h
===
--- include/bits/uses_allocator.h	(revision 278366)
+++ include/bits/uses_allocator.h	(working copy)
@@ -72,7 +72,7 @@
 
   struct __uses_alloc0 : __uses_alloc_base
   {
-struct _Sink { void operator=(const void*) { } } _M_a;
+struct _Sink { void _GLIBCXX20_CONSTEXPR operator=(const void*) { } } _M_a;
   };
 
   template
@@ -109,6 +109,7 @@
   __uses_alloc::value, _Tp, _Alloc, _Args...>;
 
   template
+_GLIBCXX20_CONSTEXPR
 inline __uses_alloc_t<_Tp, _Alloc, _Args...>
 __use_alloc(const _Alloc& __a)
 {



[PATCH, libstdc++] More

2019-11-15 Thread Ed Smith-Rowland via gcc-patches


First of all, the redo of the iterator portion in response to 
https://gcc.gnu.org/ml/gcc-patches/2019-11/msg01467.html passed testing.


This patch contains constexpr char_traits. I also found an old extension 
that had been left out of the constexpr bandwagon that I caught up.


This patch also includes constexpr string_view::copy which depends on 
teh type_traits.


This gets all of p1032 except string::copy (although constexpr 
char_traits should almost enable this too once constexpr string is in).  
I'm done.


This passes on x86_64-linux.

OK?


2019-11-16  Edward Smith-Rowland  <3dw...@verizon.net>

	Implement the char_traits and string_view part of C++20 p1032 Misc.
	constexpr bits.
	* include/bits/char_traits.h (move, copy, assign): Constexpr.
	* include/bits/stl_algobase.h (__memcpy, __memset): New.
	* include/ext/pod_char_traits.h (from, to, operator==, operator<)
	(assign, eq, lt, compare, length, find, move, copy, assign)
	(to_char_type, to_int_type, eq_int_type, eof, not_eof):
	Make these constespr for appropriate standards.
	* testsuite/21_strings/char_traits/requirements/char/constexpr.cc: New test.
	* testsuite/21_strings/char_traits/requirements/wchar_t/constexpr.cc: New test.
	* include/std/string_view (copy): Constexpr.
	* testsuite/21_strings/basic_string_view/operations/copy/char/constexpr.cc: New test.
	* testsuite/21_strings/basic_string_view/operations/copy/wchar_t/constexpr.cc: New test.

Index: include/bits/char_traits.h
===
--- include/bits/char_traits.h	(revision 278318)
+++ include/bits/char_traits.h	(working copy)
@@ -113,13 +113,13 @@
   static _GLIBCXX14_CONSTEXPR const char_type*
   find(const char_type* __s, std::size_t __n, const char_type& __a);
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   move(char_type* __s1, const char_type* __s2, std::size_t __n);
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   copy(char_type* __s1, const char_type* __s2, std::size_t __n);
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   assign(char_type* __s, std::size_t __n, char_type __a);
 
   static _GLIBCXX_CONSTEXPR char_type
@@ -179,18 +179,17 @@
 }
 
   template
-typename char_traits<_CharT>::char_type*
+_GLIBCXX20_CONSTEXPR typename char_traits<_CharT>::char_type*
 char_traits<_CharT>::
 move(char_type* __s1, const char_type* __s2, std::size_t __n)
 {
   if (__n == 0)
 	return __s1;
-  return static_cast<_CharT*>(__builtin_memmove(__s1, __s2,
-		__n * sizeof(char_type)));
+  return static_cast<_CharT*>(std::__memmove(__s1, __s2, __n));
 }
 
   template
-typename char_traits<_CharT>::char_type*
+_GLIBCXX20_CONSTEXPR typename char_traits<_CharT>::char_type*
 char_traits<_CharT>::
 copy(char_type* __s1, const char_type* __s2, std::size_t __n)
 {
@@ -200,7 +199,7 @@
 }
 
   template
-typename char_traits<_CharT>::char_type*
+_GLIBCXX20_CONSTEXPR typename char_traits<_CharT>::char_type*
 char_traits<_CharT>::
 assign(char_type* __s, std::size_t __n, char_type __a)
 {
@@ -349,28 +348,28 @@
 	return static_cast(__builtin_memchr(__s, __a, __n));
   }
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   move(char_type* __s1, const char_type* __s2, size_t __n)
   {
 	if (__n == 0)
 	  return __s1;
-	return static_cast(__builtin_memmove(__s1, __s2, __n));
+	return static_cast(std::__memmove(__s1, __s2, __n));
   }
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   copy(char_type* __s1, const char_type* __s2, size_t __n)
   {
 	if (__n == 0)
 	  return __s1;
-	return static_cast(__builtin_memcpy(__s1, __s2, __n));
+	return static_cast(std::__memcpy(__s1, __s2, __n));
   }
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   assign(char_type* __s, size_t __n, char_type __a)
   {
 	if (__n == 0)
 	  return __s;
-	return static_cast(__builtin_memset(__s, __a, __n));
+	return static_cast(std::__memset(__s, __a, __n));
   }
 
   static _GLIBCXX_CONSTEXPR char_type
@@ -458,27 +457,42 @@
 	return wmemchr(__s, __a, __n);
   }
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   move(char_type* __s1, const char_type* __s2, size_t __n)
   {
 	if (__n == 0)
 	  return __s1;
+#ifdef __cpp_lib_is_constant_evaluated
+	if (std::is_constant_evaluated())
+	  return static_cast(std::__memmove(__s1, __s2, __n));
+	else
+#endif
 	return wmemmove(__s1, __s2, __n);
   }
 
-  static char_type*
+  static _GLIBCXX20_CONSTEXPR char_type*
   copy(char_type* __s1, const char_type* __s2, size_t __n)
   {
 	if (__n == 0)
 	  return __s1;
+#ifdef __cpp_lib_is_constant_evaluated
+	if (std::is_constant_evaluated())
+	  return static_cast(std::__memcpy(__s1, __s2, __n));
+	else
+#endif
 	return 

[RFC, libstdc++] Implement C++20 P1208R6 - source_location.

2019-11-08 Thread Ed Smith-Rowland via gcc-patches
As an experiment, I took a shot at implementing source_location for 
C++20.?? This was mostly done in experimental but I wanted to try adding 
column information.?? (The experimental version just returned 0).?? I 
added __builtin_COLUMN in analogy to __builtin_LINE.?? The std version is 
also consteval so you get different results in some cases wrt 
experimental. You can diff the two 1.cc test cases in libstdc++ to see 
for yourself.


As Jonathan mentioned on IRC, we probably want a single builtin and we 
want to coordinate the name with clang (__builtin_source_location?).?? 
But this "works" and it might make useful fodder for the next round.


Ed



gcc/ChangeLog

2019-11-08  Ed Smith-Rowland  <3dw...@verizon.net>

Implement C++20 P1208R6 - source_location.  Implement column with a
__builtin_COLUMN for both std and experimental.  The std current()
is consteval.
* builtins.c (fold_builtin_COLUMN): New function.
(fold_builtin_0): Use it.
* builtins.def: Add __builtin_COLUMN.
* doc/extend.texi: Doc __builtin_COLUMN.
* testsuite/c-c++-common/builtin_location.c: __builtin_COLUMN() tests.
* testsuite/c-c++-common/cpp/has-builtin-2.c: __builtin_COLUMN test.


libstdc++-v3/ChangeLog

2019-11-08  Ed Smith-Rowland  <3dw...@verizon.net>

Implement C++20 P1208R6 - source_location.  Implement column with a
__builtin_COLUMN for both std and experimental.  The std current()
is consteval.
* include/experimental/source_location: Call __builtin_COLUMN
* include/std/source_location: New header.
* include/std/version: Add 
* testsuite/20_util/source_location/1.cc: New test.
* libstdc++-v3/testsuite/experimental/source_location/1.cc: Test column.

Index: gcc/builtins.c
===
--- gcc/builtins.c	(revision 277745)
+++ gcc/builtins.c	(working copy)
@@ -9500,6 +9500,14 @@
   return build_int_cst (type, LOCATION_LINE (loc));
 }
 
+/* Fold a call to __builtin_COLUMN to an integer constant.  */
+
+static inline tree
+fold_builtin_COLUMN (location_t loc, tree type)
+{
+  return build_int_cst (type, LOCATION_COLUMN (loc));
+}
+
 /* Fold a call to built-in function FNDECL with 0 arguments.
This function returns NULL_TREE if no simplification was possible.  */
 
@@ -9519,6 +9527,9 @@
 case BUILT_IN_LINE:
   return fold_builtin_LINE (loc, type);
 
+case BUILT_IN_COLUMN:
+  return fold_builtin_COLUMN (loc, type);
+
 CASE_FLT_FN (BUILT_IN_INF):
 CASE_FLT_FN_FLOATN_NX (BUILT_IN_INF):
 case BUILT_IN_INFD32:
Index: gcc/builtins.def
===
--- gcc/builtins.def	(revision 277745)
+++ gcc/builtins.def	(working copy)
@@ -1048,6 +1048,7 @@
 DEF_GCC_BUILTIN (BUILT_IN_FILE, "FILE", BT_FN_CONST_STRING, ATTR_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN (BUILT_IN_FUNCTION, "FUNCTION", BT_FN_CONST_STRING, ATTR_NOTHROW_LEAF_LIST)
 DEF_GCC_BUILTIN (BUILT_IN_LINE, "LINE", BT_FN_INT, ATTR_NOTHROW_LEAF_LIST)
+DEF_GCC_BUILTIN (BUILT_IN_COLUMN, "COLUMN", BT_FN_INT, ATTR_NOTHROW_LEAF_LIST)
 
 /* Synchronization Primitives.  */
 #include "sync-builtins.def"
Index: gcc/doc/extend.texi
===
--- gcc/doc/extend.texi	(revision 277745)
+++ gcc/doc/extend.texi	(working copy)
@@ -13154,6 +13154,13 @@
 of the call to @var{F}.
 @end deftypefn
 
+@deftypefn {Built-in Function} int __builtin_COLUMN ()
+This function returns a constant integer expression that evaluates to
+the column number of the invocation of the built-in.  When used as a C++
+default argument for a function @var{F}, it returns the line number
+of the call to @var{F}.
+@end deftypefn
+
 @deftypefn {Built-in Function} {const char *} __builtin_FUNCTION ()
 This function is the equivalent of the @code{__FUNCTION__} symbol
 and returns an address constant pointing to the name of the function
Index: libstdc++-v3/include/experimental/source_location
===
--- libstdc++-v3/include/experimental/source_location	(revision 277745)
+++ libstdc++-v3/include/experimental/source_location	(working copy)
@@ -52,7 +52,7 @@
 current(const char* __file = __builtin_FILE(),
 	const char* __func = __builtin_FUNCTION(),
 	int __line = __builtin_LINE(),
-	int __col = 0) noexcept
+	int __col = __builtin_COLUMN()) noexcept
 {
   source_location __loc;
   __loc._M_file = __file;
Index: libstdc++-v3/include/std/source_location
===
--- libstdc++-v3/include/std/source_location	(nonexistent)
+++ libstdc++-v3/include/std/source_location	(working copy)
@@ -0,0 +1,95 @@
+//  -*- C++ -*-
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part

Re: [PATCH, libstdc++] Doc changes for constexpr additions for C++20 status.

2019-09-09 Thread Ed Smith-Rowland via gcc-patches

On 9/9/19 5:41 AM, Jonathan Wakely wrote:

On 05/09/19 15:45 -0400, Ed Smith-Rowland via libstdc++ wrote:
Here is a patch to the libstdc++ docs re constexpr additions. They 
reflect the latest macro assignments AFAICT.


Constexpr interator reqs are implemented in 9.1, the rest for 10.1.

Ok?

Should I bother adding the Constexpr interator requirements to the 
gcc-9 branch docs?


Yes please, it would be good to have that part in the gcc-9 docs. No
need to regen the HTML on the branch at this time though.

Thanks


Ok,

I committed the attached for gcc-9.

Ed


2019-09-09  Edward Smith-Rowland  <3dw...@verizon.net>

Update docs for p858 - Constexpr iterator changes available since 9.1.
* doc/xml/manual/status_cxx2020.xml: Update p0858r0 status.

Index: doc/xml/manual/status_cxx2020.xml
===
--- doc/xml/manual/status_cxx2020.xml   (revision 275522)
+++ doc/xml/manual/status_cxx2020.xml   (working copy)
@@ -309,7 +309,6 @@
 
 
 
-  
 Constexpr iterator requirements 
   
 http://www.w3.org/1999/xlink; 
xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0858r0.html;>
@@ -316,8 +315,9 @@
P0858R0

   
-   
-  
+   9.1 
+   __cpp_lib_string_view = 201803L
+  and __cpp_lib_array_constexpr = 201803L 
 
 
 


Re: We should mark "Should Span be Regular? P1085R2" as well.

2019-09-09 Thread Ed Smith-Rowland via gcc-patches

On 9/9/19 5:38 AM, Jonathan Wakely wrote:

On 06/09/19 18:08 -0400, Ed Smith-Rowland via libstdc++ wrote:

As the title says.

 was (correctly) delivered without comparison ops. so we chould 
check off p1085.


Indeed, thanks!

This includes the status updates for constexpr lib diffs posted 
previously.


I also regenerated the html (resulted in pure boiler except for 
manual/status.html).

The boilerplate change are a bit annoying



Ok, here is what I finally committed (just two files)..

Ed


2019-09-09  Edward Smith-Rowland  <3dw...@verizon.net>

Update docs for recent  and constexpr lib changes.
* doc/xml/manual/status_cxx2020.xml: Update p0202r3, p0858r0, p0879r0,
p1023r0, p1085r2 status.
* doc/html/manual/status.html: Regenerate.

Index: doc/html/manual/status.html
===
--- doc/html/manual/status.html (revision 275477)
+++ doc/html/manual/status.html (working copy)
@@ -1061,11 +1061,11 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0053r7.pdf; 
target="_top">
P0053R7

-      Add constexpr modifiers to functions in 
algorithm and utility Headers 
+      Add constexpr modifiers to functions in algorithm and utility Headers 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html; 
target="_top">
P0202R3

-      Constexpr for std::complex 
+   10.1  __cpp_lib_constexpr_algorithms = 201703L 
  Constexpr for std::complex 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0415r1.html; 
target="_top">
P0415R1

@@ -1133,11 +1133,12 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0809r0.pdf; 
target="_top">
P0809R0

-      Constexpr iterator requirements 
+      Constexpr iterator requirements 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0858r0.html; 
target="_top">
P0858R0

-      Symmetry for spaceship 
+   9.1  __cpp_lib_string_view = 201803L
+  and __cpp_lib_array_constexpr = 201803L 
  Symmetry for spaceship 

 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0905r1.html; 
target="_top">
P0905R1

@@ -1201,11 +1202,11 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0788r3.pdf; 
target="_top">
P0788R3

-      Constexpr for swap and swap related functions 
+      Constexpr for swap and swap related 
functions 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0879r0.html; 
target="_top">
P0879R0

-      The identity metafunction 
+   10.1  __cpp_lib_constexpr_algorithms = 201806L 
  The identity 
metafunction 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0887r1.pdf; 
target="_top">
P0887R1

@@ -1225,11 +1226,11 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0941r2.html; 
target="_top">
P0941R2

-   5.1    constexpr 
comparison operators for std::array 
+   5.1    constexpr comparison operators for 
std::array 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1023r0.pdf; 
target="_top">
P1023R0

-      Update The Reference To The Unicode 
Standard 
+   10.1    Update The Reference To The Unicode 
Standard 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1025r1.html; 
target="_top">
P1025R1

@@ -1315,11 +1316,11 @@
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1032r1.html; 
target="_top">
P1032R1

-      Should Span be Regular? 
+      Should Span be Regular? 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1085r2.md; 
target="_top">
P1085R2

-      Editorial Guidance for merging P0019r8 and P0528r3 
+   10.1  __cpp_lib_span = 201902L   Editorial Guidance for merging P0019r8 and P0528r3 
 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1123r0.html; 
target="_top">
P1123R0

Index: doc/xml/manual/status_cxx2020.xml
===
--- doc/xml/manual/status_cxx2020.xml   (revision 275477)
+++ doc/xml/manual/status_cxx2020.xml   (working copy)
@@ -101,7 +101,6 @@
 
 
 
-  
 Add constexpr modifiers to functions in 
algorithm and utility Headers 
   
 http://www.w3.org/1999/xlink; 
xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html;>
@@ -108,8 +107,8 @@
P0202R3

   
-   
-  
+   10.1 
+   __cpp_lib_constexpr_algorithms = 201703L 

 
 
 
@@ -307,7 +306,

[PATCH, libstdc++] Doc changes for constexpr additions for C++20 status.

2019-09-05 Thread Ed Smith-Rowland via gcc-patches
Here is a patch to the libstdc++ docs re constexpr additions. They 
reflect the latest macro assignments AFAICT.


Constexpr interator reqs are implemented in 9.1, the rest for 10.1.

Ok?

Should I bother adding the Constexpr interator requirements to the gcc-9 
branch docs?


Ed


Index: doc/html/manual/status.html
===
--- doc/html/manual/status.html (revision 275426)
+++ doc/html/manual/status.html (working copy)
@@ -597,7 +597,7 @@
P0220R1

7.1  __has_include(string_view),
-  __cpp_lib_string_view = 201603
+  __cpp_lib_string_view = 201803
   (since 7.3, see Note 1)
Library Fundamentals V1 TS Components: 
memory_resource 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0220r1.html; 
target="_top">
@@ -778,7 +778,7 @@
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0031r0.html; 
target="_top">
P0031R0

-   7.1  
__cpp_lib_array_constexpr = 201603  The Parallelism TS Should be Standardized  

+   7.1  
__cpp_lib_array_constexpr = 201803  The Parallelism TS Should be Standardized  

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0024r2.html; 
target="_top">
P0024R2

@@ -1571,4 +1571,4 @@
Prev Up NextPart I. 
   Introduction
   
- Home 
License
\ No newline at end of file
+ Home 
License
Index: doc/xml/manual/status_cxx2020.xml
===
--- doc/xml/manual/status_cxx2020.xml   (revision 275426)
+++ doc/xml/manual/status_cxx2020.xml   (working copy)
@@ -101,7 +101,6 @@
 
 
 
-  
 Add constexpr modifiers to functions in 
algorithm and utility Headers 
   
 http://www.w3.org/1999/xlink; 
xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html;>
@@ -108,8 +107,8 @@
P0202R3

   
-   
-  
+   10.1 
+   __cpp_lib_constexpr_algorithms = 201703L 

 
 
 
@@ -307,7 +306,6 @@
 
 
 
-  
 Constexpr iterator requirements 
   
 http://www.w3.org/1999/xlink; 
xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0858r0.html;>
@@ -314,8 +312,9 @@
P0858R0

   
-   
-  
+   9.1 
+   __cpp_lib_string_view = 201803L
+  and __cpp_lib_array_constexpr = 201803L 
 
 
 
@@ -503,7 +502,6 @@
 
 
 
-  
 Constexpr for swap and swap related functions 

   
 http://www.w3.org/1999/xlink; 
xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0879r0.html;>
@@ -510,8 +508,8 @@
P0879R0

   
-   
-  
+   10.1 
+   __cpp_lib_constexpr_algorithms = 201806L 

 
 
 
@@ -571,7 +569,6 @@
 
 
 
-  
 constexpr comparison operators for 
std::array 
   
 http://www.w3.org/1999/xlink; 
xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1023r0.pdf;>
@@ -578,7 +575,7 @@
P1023R0

   
-   
+   10.1 
   
 
 


Re: Implement C++20 p1424 - 'constexpr' feature macro concerns.

2019-08-21 Thread Ed Smith-Rowland via gcc-patches

On 8/20/19 6:14 PM, Jonathan Wakely wrote:

On 16/08/19 22:39 -0400, Ed Smith-Rowland via libstdc++ wrote:
The latest draft and I guess the above paper changed the macro names 
for the C++20 constexpr lib featues.


__cpp_lib_constexpr_algorithms ->__cpp_lib_constexpr.


The __cpp_lib_constexpr macro is (now?) for a different feature.

The proposed resolution for https://cplusplus.github.io/LWG/issue3256
is to keep the __cpp_lib_constexpr_algorithms name to indicate support
for what is currently described by __cpp_lib_constexpr_swap_algorithms
(and see https://cplusplus.github.io/LWG/issue3257 for another issue
in this area)


I'm testing the attached.

I changed back to __cpp_lib_constexpr_algorithms from __cpp_lib_constexpr.

I dropped__cpp_lib_constexpr_swap_algorithms in favor of 
__cpp_lib_constexpr_algorithms.


I'm leaving __cpp_lib_constexpr alone.?? We don't test this anyway.?? It's 
sitting in .


Is it possible that __cpp_lib_constexpr_char_traits also should be 
bumped from 201611 to 201806 because of P1032 section 10? Note that I'm 
not done with this but I'd like to get ahead of the macro issues.?? 
Presumably, __cpp_lib_constexpr_algorithms gets bumped.


Ed


2019-08-22  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p1424 - 'constexpr' feature macro concerns,
Issue 3256 - Feature testing macro for constexpr algorithms,
and Issue 3257 - Missing feature testing macro update from P0858.
* include/std/version (__cpp_lib_constexpr_algorithms): Bump value.
* include/bits/algorithmfwd.h: Ditto.
* include/std/utility: Ditto.
* testsuite/25_algorithms/constexpr_macro.cc: Ditto.
* testsuite/25_algorithms/cpp_lib_constexpr.cc: New check for
__cpp_lib_constexpr macro in .
* testsuite/20_util/exchange/constexpr.cc: Add check for
__cpp_lib_constexpr macro in .
* testsuite/25_algorithms/adjacent_find/constexpr.cc: Remove check for
__cpp_lib_constexpr_algorithms.
* testsuite/25_algorithms/all_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/any_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/binary_search/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy_backward/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy_n/constexpr.cc: Ditto.
* testsuite/25_algorithms/count/constexpr.cc: Ditto.
* testsuite/25_algorithms/count_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/equal/constexpr.cc: Ditto.
* testsuite/25_algorithms/equal_range/constexpr.cc: Ditto.
* testsuite/25_algorithms/fill/constexpr.cc: Ditto.
* testsuite/25_algorithms/fill_n/constexpr.cc: Ditto.
* testsuite/25_algorithms/find/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_end/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_first_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_if_not/constexpr.cc: Ditto.
* testsuite/25_algorithms/for_each/constexpr.cc: Ditto.
* testsuite/25_algorithms/generate/constexpr.cc: Ditto.
* testsuite/25_algorithms/generate_n/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_heap/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_heap_until/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_partitioned/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_permutation/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_sorted/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_sorted_until/constexpr.cc: Ditto.
* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: Ditto.
* testsuite/25_algorithms/lower_bound/constexpr.cc: Ditto.
* testsuite/25_algorithms/merge/constexpr.cc: Ditto.
* testsuite/25_algorithms/mismatch/constexpr.cc: Ditto.
* testsuite/25_algorithms/none_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/partition_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/partition_point/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove_copy_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/replace_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/replace_copy_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/replace_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/reverse_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/rotate_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/search/constexpr.cc: Ditto.
* testsuite/25_algorithms/search_n/constexpr.cc: Ditto.
* 

Implement C++20 p1424 - 'constexpr' feature macro concerns.

2019-08-16 Thread Ed Smith-Rowland via gcc-patches
The latest draft and I guess the above paper changed the macro names for 
the C++20 constexpr lib featues.


__cpp_lib_constexpr_algorithms ->__cpp_lib_constexpr.

This patch changes the name but not the date because I still have some 
work to do before I can ship the "miscellaneous" constexpr material.


I would like to slot this patch in before that chunk 3 of the constexpr 
lib patch set rather than wait because it simplifies the testing of 
macros somewhat.


I would also like to kill a non-standard macro pretty quickly.

It is a trivial patch really and it built and tested cleanly on 
x86_64-linux.


Ok for mainline?

Ed


2019-08-19  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p1424 - 'constexpr' feature macro concerns.
* include/std/version (__cpp_lib_constexpr_algorithms): Change macro
name to __cpp_lib_constexpr.
* include/bits/algorithmfwd.h: Ditto.
* include/std/utility: Ditto.
* testsuite/25_algorithms/constexpr_macro.cc: Ditto.
* testsuite/25_algorithms/cpp_lib_constexpr.cc: New check for
__cpp_lib_constexpr macro in .
* testsuite/20_util/exchange/constexpr.cc: Add check for
__cpp_lib_constexpr macro in .
* testsuite/25_algorithms/adjacent_find/constexpr.cc: Remove check for
__cpp_lib_constexpr_algorithms (now __cpp_lib_constexpr) in .
* testsuite/25_algorithms/all_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/any_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/binary_search/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy_backward/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/copy_n/constexpr.cc: Ditto.
* testsuite/25_algorithms/count/constexpr.cc: Ditto.
* testsuite/25_algorithms/count_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/equal/constexpr.cc: Ditto.
* testsuite/25_algorithms/equal_range/constexpr.cc: Ditto.
* testsuite/25_algorithms/fill/constexpr.cc: Ditto.
* testsuite/25_algorithms/fill_n/constexpr.cc: Ditto.
* testsuite/25_algorithms/find/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_end/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_first_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/find_if_not/constexpr.cc: Ditto.
* testsuite/25_algorithms/for_each/constexpr.cc: Ditto.
* testsuite/25_algorithms/generate/constexpr.cc: Ditto.
* testsuite/25_algorithms/generate_n/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_heap/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_heap_until/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_partitioned/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_permutation/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_sorted/constexpr.cc: Ditto.
* testsuite/25_algorithms/is_sorted_until/constexpr.cc: Ditto.
* testsuite/25_algorithms/lexicographical_compare/constexpr.cc: Ditto.
* testsuite/25_algorithms/lower_bound/constexpr.cc: Ditto.
* testsuite/25_algorithms/merge/constexpr.cc: Ditto.
* testsuite/25_algorithms/mismatch/constexpr.cc: Ditto.
* testsuite/25_algorithms/none_of/constexpr.cc: Ditto.
* testsuite/25_algorithms/partition_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/partition_point/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove_copy_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/remove_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/replace_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/replace_copy_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/replace_if/constexpr.cc: Ditto.
* testsuite/25_algorithms/reverse_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/rotate_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/search/constexpr.cc: Ditto.
* testsuite/25_algorithms/search_n/constexpr.cc: Ditto.
* testsuite/25_algorithms/set_difference/constexpr.cc: Ditto.
* testsuite/25_algorithms/set_intersection/constexpr.cc: Ditto.
* testsuite/25_algorithms/set_symmetric_difference/constexpr.cc: Ditto.
* testsuite/25_algorithms/set_union/constexpr.cc: Ditto.
* testsuite/25_algorithms/transform/constexpr.cc: Ditto.
* testsuite/25_algorithms/unique/constexpr.cc: Ditto.
* testsuite/25_algorithms/unique_copy/constexpr.cc: Ditto.
* testsuite/25_algorithms/upper_bound/constexpr.cc: Ditto.

Index: include/bits/algorithmfwd.h
===
--- 

Re: [PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions.

2019-08-14 Thread Ed Smith-Rowland via gcc-patches

On 8/13/19 7:14 AM, Jonathan Wakely wrote:

On 01/08/19 13:16 -0400, Ed Smith-Rowland via libstdc++ wrote:

Greetings,

Here is a patch for C++20 p0879 - Constexpr for swap and swap related 
functions.


This essentially constexprifies the rest of .

Built and tested with C++20 (and pre-c++20) on x86_64-linux.

Ok?

Regards,

Ed Smith-Rowland





2019-08-01?? Edward Smith-Rowland <3dw...@verizon.net>

Implement C++20 p0879 - Constexpr for swap and swap related 
functions.

* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
New macro. (iter_swap, make_heap, next_permutation, 
partial_sort_copy,


There should be a newline after "New macro." and before the next
parenthesized list of identifiers.

The parenthesized lists should not span multiple lines, so close and
reopen the parens, i.e.

 Implement C++20 p0879 - Constexpr for swap and swap related 
functions.
 * include/bits/algorithmfwd.h 
(__cpp_lib_constexpr_swap_algorithms):

 New macro.
 (iter_swap, make_heap, next_permutation, partial_sort_copy, 
pop_heap)

 (prev_permutation, push_heap, reverse, rotate, sort_heap, swap)
 (swap_ranges, nth_element, partial_sort, sort): Add constexpr.


@@ -193,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

#if __cplusplus > 201703L
#?? define __cpp_lib_constexpr_algorithms 201711L
+#?? define __cpp_lib_constexpr_swap_algorithms 201712L


Should this value be 201806L?

Indeed.


The new macro also needs to be added to .


Done.

I this OK after it passes testing?

Ed



2019-08-14  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0879 - Constexpr for swap and swap related functions.
* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
New macro.
* include/std/version: Ditto.
(iter_swap, make_heap, next_permutation, partial_sort_copy, pop_heap)
(prev_permutation, push_heap, reverse, rotate, sort_heap, swap)
(swap_ranges, nth_element, partial_sort, sort): Add constexpr.
* include/bits/move.h (swap): Add constexpr.
* include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse)
(__gcd, __rotate, rotate, __partition, __heap_select)
(__partial_sort_copy, partial_sort_copy, __unguarded_partition)
(__unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort)
(__introselect, __chunk_insertion_sort, next_permutation)
(prev_permutation, partition, partial_sort, nth_element, sort)
(__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr.
* include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap)
(swap_ranges): Add constexpr.
* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
__pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap):
Add constexpr.
* include/std/type_traits (swap): Add constexpr.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Add constexpr.
* testsuite/25_algorithms/iter_swap/constexpr.cc: New test.
* testsuite/25_algorithms/make_heap/constexpr.cc: New test.
* testsuite/25_algorithms/next_permutation/constexpr.cc: New test.
* testsuite/25_algorithms/nth_element/constexpr.cc: New test.
* testsuite/25_algorithms/partial_sort/constexpr.cc: New test.
* testsuite/25_algorithms/partial_sort_copy/constexpr.cc: New test.
* testsuite/25_algorithms/partition/constexpr.cc: New test.
* testsuite/25_algorithms/pop_heap/constexpr.cc: New test.
* testsuite/25_algorithms/prev_permutation/constexpr.cc: New test.
* testsuite/25_algorithms/push_heap/constexpr.cc: New test.
* testsuite/25_algorithms/reverse/constexpr.cc: New test.
* testsuite/25_algorithms/rotate/constexpr.cc: New test.
* testsuite/25_algorithms/sort/constexpr.cc: New test.
* testsuite/25_algorithms/sort_heap/constexpr.cc: New test.
* testsuite/25_algorithms/swap/constexpr.cc: New test.
* testsuite/25_algorithms/swap_ranges/constexpr.cc: New test.

Index: include/bits/algorithmfwd.h
===
--- include/bits/algorithmfwd.h (revision 274411)
+++ include/bits/algorithmfwd.h (working copy)
@@ -193,6 +193,7 @@
 
 #if __cplusplus > 201703L
 #  define __cpp_lib_constexpr_algorithms 201711L
+#  define __cpp_lib_constexpr_swap_algorithms 201806L
 #endif
 
 #if __cplusplus >= 201103L
@@ -377,6 +378,7 @@
 #endif
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 iter_swap(_FIter1, _FIter2);
 
@@ -391,10 +393,12 @@
 lower_bound(_FIter, _FIter, const _Tp&, _Compare);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 make_heap(_RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 make_heap(_RAIter, _RAIter, _Compare);
 
@@ -478,10 +482

Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-08-07 Thread Ed Smith-Rowland via gcc-patches

On 8/6/19 11:30 AM, Steve Ellcey wrote:

Ed,

I have run into an ICE that I tracked down to this patch:

commit 02fefffe6b78c4c39169206aa40fb53f367ecba8
Author: emsr 
Date:   Thu Aug 1 15:25:42 2019 +

 2019-08-01  Edward Smith-Rowland  <3dw...@verizon.net>

 Implement C++20 p0202 - Add Constexpr Modifiers to Functions
 in  and  Headers.
 Implement C++20 p1023 - constexpr comparison operators for 
std::array.


Before I try to create a smaller test example (the current failure happens
when I build https://github.com/llnl/RAJAPerf.git) I was wondering if you
have already seen this ICE:

/extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp: In member 
function 'virtual void rajaperf::apps::COUPLE::runKernel(rajaperf::VariantID)':
/extra/sellcey/raja-build-error/RAJAPerf/src/apps/WIP-COUPLE.cpp:217:1: 
internal compiler error: Segmentation fault
   217 | } // end namespace rajaperf
   | ^
0xe81ddf crash_signal
../../gcc/gcc/toplev.c:326
0x968d14 lookup_page_table_entry
../../gcc/gcc/ggc-page.c:632
0x968d14 ggc_set_mark(void const*)
../../gcc/gcc/ggc-page.c:1531
0xbfeadf gt_ggc_mx_symtab_node(void*)
/extra/sellcey/gcc-tot/obj-gcc/gcc/gtype-desc.c:1302
0xd9d2a7 gt_ggc_ma_order
./gt-passes.h:31
0xd9d2a7 gt_ggc_ma_order
./gt-passes.h:26
0xb6f49f ggc_mark_root_tab
../../gcc/gcc/ggc-common.c:77
0xb6f6c3 ggc_mark_roots()
../../gcc/gcc/ggc-common.c:94
0x9696af ggc_collect()
../../gcc/gcc/ggc-page.c:2201
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.


I've been building C++14 code (and C++17 and C++20 code) with this patch 
for half a year and no ICE.


I don't see how the patch could impact pre C++20 code.

Ed




Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-08-01 Thread Ed Smith-Rowland via gcc-patches

On 8/1/19 3:45 PM, Jonathan Wakely wrote:

On 01/08/19 11:47 -0400, Ed Smith-Rowland via libstdc++ wrote:

On 8/1/19 6:56 AM, Jonathan Wakely wrote:

On 31/07/19 10:50 -0400, Ed Smith-Rowland via libstdc++ wrote:

Here is the patch for

* Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
 and  Headers.


* Implement C++20 p1023 - constexpr comparison operators for 
std::array.


Relative to the last effort it is rebased on more recent trunk and 
I added to .


There's some chance that I'll have to tweak the macros after the 
draft comes in but I'd like to get this moving.?? I've got other 
chunks of constexpr lib coming.?? This passes C++20 testing 
onx86_64-linux.


Ok?


Calls to the new __memmove and __memcmp functions need to be qualified
with std:: to prevent ADL. I think we should rename those functions,
but that can happen later.


IMHO, these concepts are too important to leave as an implementation 
detail.


I suspect the committee will come crawling back to specify these with 
real names.


memory_copy, memory_compare, memory_move for C++23 anyone?


trivial_copy, trivial_compare, trivial_move


Works for me. I'm sure there will be great bikeshed battles!

Ed




[PATCH 2/3] C++20 constexpr lib part 2/3 - swappish functions.

2019-08-01 Thread Ed Smith-Rowland via gcc-patches

Greetings,

Here is a patch for C++20 p0879 - Constexpr for swap and swap related 
functions.


This essentially constexprifies the rest of .

Built and tested with C++20 (and pre-c++20) on x86_64-linux.

Ok?

Regards,

Ed Smith-Rowland


2019-08-01  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0879 - Constexpr for swap and swap related functions.
* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
New macro. (iter_swap, make_heap, next_permutation, partial_sort_copy,
pop_heap, prev_permutation, push_heap, reverse, rotate, sort_heap,
swap, swap_ranges, nth_element, partial_sort, sort): Add constexpr.
* include/bits/move.h (swap): Add constexpr.
* include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse,
__gcd, __rotate, rotate, __partition, __heap_select,
__partial_sort_copy, partial_sort_copy, __unguarded_partition,
__unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort,
__introselect, __chunk_insertion_sort, next_permutation,
prev_permutation, partition, partial_sort, nth_element, sort,
__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr.
* include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap,
swap_ranges): Add constexpr.
* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
__pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap):
Add constexpr.
* include/std/type_traits (swap): Add constexpr.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Add constexpr.
* testsuite/25_algorithms/iter_swap/constexpr.cc: New test.
* testsuite/25_algorithms/make_heap/constexpr.cc: New test.
* testsuite/25_algorithms/next_permutation/constexpr.cc: New test.
* testsuite/25_algorithms/nth_element/constexpr.cc: New test.
* testsuite/25_algorithms/partial_sort/constexpr.cc: New test.
* testsuite/25_algorithms/partial_sort_copy/constexpr.cc: New test.
* testsuite/25_algorithms/partition/constexpr.cc: New test.
* testsuite/25_algorithms/pop_heap/constexpr.cc: New test.
* testsuite/25_algorithms/prev_permutation/constexpr.cc: New test.
* testsuite/25_algorithms/push_heap/constexpr.cc: New test.
* testsuite/25_algorithms/reverse/constexpr.cc: New test.
* testsuite/25_algorithms/rotate/constexpr.cc: New test.
* testsuite/25_algorithms/sort/constexpr.cc: New test.
* testsuite/25_algorithms/sort_heap/constexpr.cc: New test.
* testsuite/25_algorithms/swap/constexpr.cc: New test.
* testsuite/25_algorithms/swap_ranges/constexpr.cc: New test.

diff --git a/libstdc++-v3/include/bits/algorithmfwd.h 
b/libstdc++-v3/include/bits/algorithmfwd.h
index 99491db1c5e..24b6849e53e 100644
--- a/libstdc++-v3/include/bits/algorithmfwd.h
+++ b/libstdc++-v3/include/bits/algorithmfwd.h
@@ -193,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus > 201703L
 #  define __cpp_lib_constexpr_algorithms 201711L
+#  define __cpp_lib_constexpr_swap_algorithms 201712L
 #endif
 
 #if __cplusplus >= 201103L
@@ -377,6 +378,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 iter_swap(_FIter1, _FIter2);
 
@@ -391,10 +393,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 lower_bound(_FIter, _FIter, const _Tp&, _Compare);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 make_heap(_RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 make_heap(_RAIter, _RAIter, _Compare);
 
@@ -478,10 +482,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // mismatch
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 next_permutation(_BIter, _BIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 next_permutation(_BIter, _BIter, _Compare);
 
@@ -496,10 +502,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // partial_sort
 
   template
+_GLIBCXX20_CONSTEXPR
 _RAIter
 partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 _RAIter
 partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare);
 
@@ -519,26 +527,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 pop_heap(_RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 pop_heap(_RAIter, _RAIter, _Compare);
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 prev_permutation(_BIter, _BIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 prev_permutation(_BIter, _BIter, _Compare);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 push_heap(_RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 push_heap(_RAIter, _RAIter, _Compare);
 
@@ -579,6 +593,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // replace_if
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 reverse(_BIter, _BIter);
 

Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-08-01 Thread Ed Smith-Rowland via gcc-patches

On 8/1/19 6:56 AM, Jonathan Wakely wrote:

On 31/07/19 10:50 -0400, Ed Smith-Rowland via libstdc++ wrote:

Here is the patch for

* Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
 and  Headers.


* Implement C++20 p1023 - constexpr comparison operators for std::array.

Relative to the last effort it is rebased on more recent trunk and I 
added to .


There's some chance that I'll have to tweak the macros after the 
draft comes in but I'd like to get this moving.?? I've got other 
chunks of constexpr lib coming.?? This passes C++20 testing 
onx86_64-linux.


Ok?


Calls to the new __memmove and __memcmp functions need to be qualified
with std:: to prevent ADL. I think we should rename those functions,
but that can happen later.


IMHO, these concepts are too important to leave as an implementation detail.

I suspect the committee will come crawling back to specify these with 
real names.


memory_copy, memory_compare, memory_move for C++23 anyone?


The new 23_containers/array/comparison_operators/constexpr.cc test
will be UNSUPPORTED by default because it doesn't have the directive
{ dg-options "-std=gnu++2a" }.

The change to the  header defines __cpp_lib_constexpr instead
of __cpp_lib_constexpr_algorithms as it should be. For some recent
changes I've added a testcase that does nothing but include 
and check the feature test macro, which ensures that it's set
correctly by  not just by the other header(s) defining it.
For example, see testsuite/26_numerics/numbers/2.cc added yesterday.

I'll add a testcase.

I wonder if the feature test macro should only be defined when
__cpp_lib_is_constant_evaluated is defined, because otherwise some
algos will not be usable constant expressions (e.g. when compiled with
Clang 7.0).

We can do this later if we need to.


OK for trunk with:

- std:: qualification on the new __mem* functions;

Done.

- the dg-options added to the testcase;

Done.

- fix the macro in  (and ideally add a test for it).

Done.

Thanks.


Committed with 273975.?? Final patch and CL attached.

Regards,

Ed


2019-08-01  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
none_of, partition_copy, partition_point, remove, remove_if,
remove_copy, remove_copy_if, replace_copy, replace_copy_if,
reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
count_if, equal, find, find_first_of, find_if, for_each, generate,
generate_n, lexicographical_compare, merge, mismatch, replace,
replace_if, search, search_n, set_difference, set_intersection,
set_symmetric_difference, set_union, transform, unique_copy):
Mark constexpr.
* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
* include/bits/predefined_ops.h (_Iter_less_val::operator(),
_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
 Use const ref instead of ref arg;
(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
__iter_comp_iter): Mark constexpr.
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,

Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-07-31 Thread Ed Smith-Rowland via gcc-patches

Here is the patch for

* Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
 and  Headers.


* Implement C++20 p1023 - constexpr comparison operators for std::array.

Relative to the last effort it is rebased on more recent trunk and I 
added to .


There's some chance that I'll have to tweak the macros after the draft 
comes in but I'd like to get this moving.?? I've got other chunks of 
constexpr lib coming.?? This passes C++20 testing onx86_64-linux.


Ok?


2019-07-31  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
none_of, partition_copy, partition_point, remove, remove_if,
remove_copy, remove_copy_if, replace_copy, replace_copy_if,
reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
count_if, equal, find, find_first_of, find_if, for_each, generate,
generate_n, lexicographical_compare, merge, mismatch, replace,
replace_if, search, search_n, set_difference, set_intersection,
set_symmetric_difference, set_union, transform, unique_copy):
Mark constexpr.
* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
* include/bits/predefined_ops.h (_Iter_less_val::operator(),
_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
 Use const ref instead of ref arg;
(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
__iter_comp_iter): Mark constexpr.
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
set_intersection, __set_difference, set_difference,
__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
wrappers around __builtin_memmove and __builtin_memcmp
respectively;
(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
copy, move, __copy_move_b, __copy_move_backward_a,
__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
__lexicographical_compare_impl, __lexicographical_compare,
__lexicographical_compare::__lc, __lexicographical_compare_aux,
__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
is_heap): Mark constexpr.
* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
is_heap): Mark constexpr.
* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark 
constexpr.
* include/std/array: Make comparison ops constexpr.
* include/std/utility: Make exchange constexpr.
* include/std/version (__cpp_lib_constexpr): New macro.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
* testsuite/23_containers/array/tuple_interface/
tuple_element_neg.cc: Adjust.
* testsuite/20_util/exchange/constexpr.cc: New.
* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
* 

Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-07-11 Thread Ed Smith-Rowland via gcc-patches

On 7/6/19 3:55 AM, Ville Voutilainen wrote:

Blargh!

But that's fine; the result of copy is not stored in a constexpr
variable, but the function return
is static_asserted so we have sufficiently tested that std::copy is
indeed constexpr-compatible
since it appears in a function that is evaluated at compile-time.


Ping?



Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-07-05 Thread Ed Smith-Rowland via gcc-patches

On 7/2/19 8:11 AM, Jonathan Wakely wrote:

One more comment. In  this:

+#if __cplusplus > 201703L \
+?? && defined(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED)
+?? if (__builtin_is_constant_evaluated())

can be simplified to just:

#ifdef __cpp_lib_is_constant_evaluated
 if (std::is_constant_evaluated())

The feature test macro is exactly the check we want here


This is done and the test cases for the non-modifying algorithms are done.

I'm was stumped on the modifying algos though.?? Consider std::copy:

-

constexpr bool
test()
{
?? constexpr std::array ca0{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
11}};

?? std::array ma0{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};

?? constexpr auto out6 = std::copy(ca0.begin(), ca0.begin() + 8, 
ma0.begin() + 2);


?? return out6 == ma0.begin() + 10;
}

static_assert(test());
-

This is essentially the same as the Boost test case referenced in p0202.

I've also taken the arrays out as globals with the same result either way:

-

ed@bad-horse:~/cxx_constexpr_lib$ ../bin_constexpr_lib/bin/g++ 
-std=gnu++2a -c testsuite/25_algorithms/copy/constexpr.cc
testsuite/25_algorithms/copy/constexpr.cc: In function ???constexpr bool 
test()???:
testsuite/25_algorithms/copy/constexpr.cc:36:34: in ???constexpr??? 
expansion of ???std::copy(ca0.std::array12>::begin(), (ca0.std::array::begin() + 32), 
(ma0.std::array::begin() + 8))???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:535:7: 
in ???constexpr??? expansion of ???std::__copy_move_a2int*>(std::__miter_base(__first), std::__miter_baseint*>(__last), __result)???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:501:30: 
in ???constexpr??? expansion of ???std::__copy_move_aint*>(std::__niter_base(__first), std::__niter_baseint*>(__last), std::__niter_base(__result))???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:463:30: 
in ???constexpr??? expansion of ???std::__copy_movestd::random_access_iterator_tag>::__copy_m(__first, __last, __result)???
/home/ed/bin_constexpr_lib/include/c++/10.0.0/bits/stl_algobase.h:445:24: 
in ???constexpr??? expansion of ???std::__memmove(__result, 
__first, ((std::size_t)((std::ptrdiff_t)_Num)))???
testsuite/25_algorithms/copy/constexpr.cc:36:80: error: modification of 
???ma0??? is not a constant expression
 36 | constexpr auto out6 = std::copy(ca0.begin(), ca0.begin() + 8, 
ma0.begin() + 2);

| ^
testsuite/25_algorithms/copy/constexpr.cc: At global scope:
testsuite/25_algorithms/copy/constexpr.cc:41:19: error: non-constant 
condition for static assertion

 41 | static_assert(test());
?? | ^~

-

By my reckoning, you have a constexpr source array, an output array that 
is initialized as it must be for constexpr.?? You have to have a 
deterministic result after the copy.?? In the local array version the 
actual iterator is not leaking out - just the results of a calculation 
that must return one result.


The only thing that 'helps' is removing the constexpr from the iterator 
return and of course that's the whole point of the thing.


Blargh!

So, you can't modify a constexpr sequence. No actual surprise.?? The 
returned iterators into non-constexpr sequences can never be literals.?? 
What you *can* do is make the modifying algorithms so you can make pure 
functions with them.?? In this connection my previous testcases for 
non-modifying?? were correct, just not complete because there the 
returned iterators into constexpr sequences can be (must be) literals.


So here is a new patch for chunk 1 of constexpr library.

Tested with default settings and with -std=gnu++2a on x86_64-linux.

OK?

Ed


2019-07-08  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
none_of, partition_copy, partition_point, remove, remove_if,
remove_copy, remove_copy_if, replace_copy, replace_copy_if,
reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
count_if, equal, find, find_first_of, find_if, for_each, generate,
generate_n, lexicographical_compare, merge, mismatch, replace,
replace_if, search, search_n, set_difference, set_intersection,
set_symmetric_difference, set_union, transform, unique_copy):
Mark constexpr.
* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
* include/bits/predefined_ops.h 

Re: Fail building modula2.

2019-06-30 Thread Ed Smith-Rowland via gcc-patches

Gaius,

I missed the fact that there are two patch sets.?? Things built like a 
charm.?? Testing now.


Thank you.

Ed




Fail building modula2.

2019-06-28 Thread Ed Smith-Rowland via gcc-patches

Gaius,

I tried to apply your patch and build and got the following error:
--

/home/ed/obj_modula2/./prev-gcc/xg++ -B/home/ed/obj_modula2/./prev-gcc/ 
-B/home/ed/bin_modula2/x86_64-pc-linux-gnu/bin/ -nostdinc++ 
-B/home/ed/obj_modula2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs 
-B/home/ed/obj_modula2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs 
-I/home/ed/obj_modula2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu 
-I/home/ed/obj_modula2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include 
-I/home/ed/gcc_git/libstdc++-v3/libsupc++ 
-L/home/ed/obj_modula2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs 
-L/home/ed/obj_modula2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs 
-fno-PIE -g -O2 -fno-checking -gtoggle -DIN_GCC -fno-exceptions 
-fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing 
-Wwrite-strings -Wcast-qual -Wno-error=format-diag?? -fno-common?? 
-DHAVE_CONFIG_H -I. -Im2 -I../../gcc_git/gcc -I../../gcc_git/gcc/m2 
-I../../gcc_git/gcc/../include -I../../gcc_git/gcc/../libcpp/include 
-I/home/ed/obj_modula2/./gmp -I/home/ed/gcc_git/gmp 
-I/home/ed/obj_modula2/./mpfr/src -I/home/ed/gcc_git/mpfr/src 
-I/home/ed/gcc_git/mpc/src?? -I../../gcc_git/gcc/../libdecnumber 
-I../../gcc_git/gcc/../libdecnumber/bid -I../libdecnumber 
-I../../gcc_git/gcc/../libbacktrace -I/home/ed/obj_modula2/./isl/include 
-I/home/ed/gcc_git/isl/include?? \
 -DSTANDARD_STARTFILE_PREFIX=\"../../../\" 
-DSTANDARD_EXEC_PREFIX=\"/home/ed/bin_modula2/lib/gcc/\" 
-DSTANDARD_LIBEXEC_PREFIX=\"/home/ed/bin_modula2/libexec/gcc/\" 
-DDEFAULT_TARGET_VERSION=\"10.0.0\" 
-DDEFAULT_REAL_TARGET_MACHINE=\"x86_64-pc-linux-gnu\" 
-DDEFAULT_TARGET_MACHINE=\"x86_64-pc-linux-gnu\" 
-DSTANDARD_BINDIR_PREFIX=\"/home/ed/bin_modula2/bin/\" 
-DTOOLDIR_BASE_PREFIX=\"../../../../\" -DACCEL_DIR_SUFFIX=\"\" 
-DENABLE_SHARED_LIBGCC -DCONFIGURE_SPECS="\"\"" 
-DTOOL_INCLUDE_DIR=\"/home/ed/bin_modula2/lib/gcc/x86_64-pc-linux-gnu/10.0.0/../../../../x86_64-pc-linux-gnu/include\" 
-DNATIVE_SYSTEM_HEADER_DIR=\"/usr/include\" \

-DLIBSUBDIR=\"/home/ed/bin_modula2/lib/gcc/x86_64-pc-linux-gnu/10.0.0\" \
?? -DPREFIX=\"/home/ed/bin_modula2\" \
?? -c ../../gcc_git/gcc/m2/gm2spec.c -o 
m2/gm2spec.o)
../../gcc_git/gcc/m2/gm2spec.c: In function ???void add_B_prefix(unsigned 
int*, cl_decoded_option**)???:
../../gcc_git/gcc/m2/gm2spec.c:275:11: error: ???fe_B_prefix??? was not 
declared in this scope; did you mean ???add_B_prefix

?? 275 | fe_B_prefix (xstrdup (path));
?? | ^~~
?? | add_B_prefix
../../gcc_git/gcc/m2/gm2spec.c: In function ???const char* no_link(int, 
const char**)???:
../../gcc_git/gcc/m2/gm2spec.c:1406:3: error: ???allow_linker??? was not 
declared in this scope

??1406 | allow_linker = FALSE;
?? | ^~~~
../../gcc_git/gcc/m2/gm2spec.c: In function ???void 
lang_register_spec_functions()???:
../../gcc_git/gcc/m2/gm2spec.c:1416:3: error: ???fe_add_spec_function??? was 
not declared in this scope; did you mean ???spec_function

??1416 | fe_add_spec_function ("objects", get_objects);
?? | ^~~~
?? | spec_function
../../gcc_git/gcc/m2/Make-lang.in:59: recipe for target 'm2/gm2spec.o' 
failed

make[3]: *** [m2/gm2spec.o] Error 1
make[3]: Leaving directory '/home/ed/obj_modula2/gcc'
Makefile:4734: recipe for target 'all-stage2-gcc' failed
make[2]: *** [all-stage2-gcc] Error 2
make[2]: Leaving directory '/home/ed/obj_modula2'
Makefile:26901: recipe for target 'stage2-bubble' failed
make[1]: *** [stage2-bubble] Error 2
make[1]: Leaving directory '/home/ed/obj_modula2'
Makefile:1002: recipe for target 'all' failed
make: *** [all] Error 2

--

Thanks,

Ed Smith-Rowland




Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-06-27 Thread Ed Smith-Rowland via gcc-patches

On 6/27/19 1:06 PM, Ville Voutilainen wrote:

On Thu, 27 Jun 2019 at 19:55, Ed Smith-Rowland via libstdc++
 wrote:

I don't think this will work in a constant expression:

?? /// Assign @p __new_val to @p __obj and return its previous value.
?? template 
+?? _GLIBCXX20_CONSTEXPR
?? inline _Tp
?? exchange(_Tp& __obj, _Up&& __new_val)
?? { return std::__exchange(__obj, std::forward<_Up>(__new_val)); }

Because std::__exchange hasn't been marked constexpr. The test passes
because it doesn't call it in a context that requires constant
evaluation:

??const auto x = std::exchange(e, pi);

Derp.

I see the same problem in other tests too:

+?? constexpr std::array car{{0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 9,
11}};
+
+?? const auto out0x = std::adjacent_find(car.begin(), car.end());
+
+?? const auto out1x = std::adjacent_find(car.begin(), car.end(),
+?? std::equal_to())

I will go through all the tests and make sure that some nontrivial
calculation is done that contributes to a final bool return.?? And clean
up the mess.?? I did this in chunk 2 but I guess I left a lot of chunk 1.

As was the case with the iterator patch, it's not a question of doing
a nontrivial calculation, but
a question of initializing a constexpr variable with the result. (Yeah
sure a non-type template
argument would also work but eurgh). Then, and only then, have we
proven that the code
works in a constexpr context. Initializing a const doesn't do that.
constinit would, but that's
C++20.


Ok, why isn't

?? static_assert(test());

a constexpr context?

The std::exchange test passed originally because, unlike all the other 
algo tests I had neglected to call the test function in a constexpr context.


Note that constexpr_iter.c is this:



constexpr int
test()
{
?? constexpr std::array a1{{1, 2, 3}};
?? static_assert(1 == *a1.begin());
?? auto n = a1[0] * a1[1]* a1[2];
?? static_assert(1 == *a1.cbegin());

?? std::array a2{{0, 0, 0}};
?? auto a1i = a1.begin();
?? auto a1e = a1.end();
?? auto a2i = a2.begin();
?? while (a1i != a1e)
?? *a2i++ = *a1i++;

?? return n;
}

void
run_test()
{
?? constexpr int n = test();
}



Things inside the function can, and in many cases for this capability 
must, be mutable.?? As long as the input and the final output is a 
literal we should be good, no?


Also when I assign returned iterators to constexpr I get:

/home/ed/gcc_git/libstdc++-v3/testsuite/25_algorithms/find_if_not/constexpr.cc:36: 
error: '(((std::array::const_pointer)(& ca0.std::array12>::_M_elems)) + 28)' is not a constant expression.




Re: [PATCH 1/3] C++20 constexpr lib part 1/3

2019-06-27 Thread Ed Smith-Rowland via gcc-patches

On 6/27/19 11:41 AM, Jonathan Wakely wrote:

On 26/06/19 19:13 -0400, Ed Smith-Rowland via libstdc++ wrote:

Here is the first of three patches for C++20 constexpr library.

?? Implement C++20 p0202 - Add constexpr Modifiers to Functions 
in  and  Headers.
 ??Implement C++20 p1023 - constexpr comparison operators for 
std::array.


I believe I have answered peoples concerns with the last patch 
attempts [https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].


The patch is large because of test cases but really just boils down 
to adding constexpr for c++2a.


I still have some concerns about the changes like:

?? template
+?? _GLIBCXX20_CONSTEXPR
?? bool
-?? operator()(_Iterator __it, _Value& __val) const
+?? operator()(_Iterator __it, const _Value& __val) const
?? { return *__it < __val; }

Make a type where operator< changes the rhs.?? I was thinking you'd want 
a compare to operate on const things but I guess we have to be ready for 
anything.?? I was also thinking < is left associative for a class member 
but i guess a class could have a thing that mutates the rhs too.?? 
Nothing got hit in any of my testing.?? If this is a thing we probably 
should make a general test for things like this somewhere.?? Maybe 
someone wants to log references or something.


1. I'll experiment to see if I really need these (I *thought* I did, but...)

2. If I still do then I'll make overloads?



I think that might change semantics for some types, and I haven't yet
figured out if we care about those cases or not. I'll try to come up
with some examples that change meaning.

This could use _GLIBCXX14_CONSTEXPR:

+?? /**
+ * A constexpr wrapper for __builtin_memmove.
+ * @param __num The number of elements of type _Tp (not bytes).

I don't think we want a Doxygen comment for this, as it's not part of
the public API. Just a normal comment is fine.

+ */
+?? template
+?? _GLIBCXX20_CONSTEXPR
+?? inline void*
+?? __memmove(_Tp* __dst, const _Tp* __src, size_t __num)
+?? {
+#if __cplusplus > 201703L \
+?? && defined(_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED)
+?? if (__builtin_is_constant_evaluated())
+?? {
+?? for(; __num > 0; --__num)
+?? {
+?? if constexpr (_IsMove)
+?? *__dst = std::move(*__src);
+?? else
+?? *__dst = *__src;

Do we need this _IsMove condition here? We should only be using this
function for trivially copyable types, in which case copy vs move
shouldn't matter, should it?

Oh ... is it because we also end up using this __memmove function for
non-trivially copyable types, during constant evaluation? Hmm. Then
it's more than just a wrapper for __builtin_memmove, right? It's
"either memmove or constexpr range copy", or something.


Yup.?? I'm also bad at naming things.?? Furthermore, I expect the 
standards people to want to have our versions of memcpy, memcmp, memmove 
that we own and can make constexpr.?? These are such important concepts.


Also, part 2 brings in constexpr swap. Maybe this is the may to 
implement an actual memmove?




I don't think this will work in a constant expression:

?? /// Assign @p __new_val to @p __obj and return its previous value.
?? template 
+?? _GLIBCXX20_CONSTEXPR
?? inline _Tp
?? exchange(_Tp& __obj, _Up&& __new_val)
?? { return std::__exchange(__obj, std::forward<_Up>(__new_val)); }

Because std::__exchange hasn't been marked constexpr. The test passes
because it doesn't call it in a context that requires constant
evaluation:

??const auto x = std::exchange(e, pi);

Derp.


I see the same problem in other tests too:

+?? constexpr std::array car{{0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 9, 
11}};

+
+?? const auto out0x = std::adjacent_find(car.begin(), car.end());
+
+?? const auto out1x = std::adjacent_find(car.begin(), car.end(),
+?? std::equal_to())


I will go through all the tests and make sure that some nontrivial 
calculation is done that contributes to a final bool return.?? And clean 
up the mess.?? I did this in chunk 2 but I guess I left a lot of chunk 1.


Come to think of it, we could build *insane* concepts after this.?? For 
good or ill.


Ed



[PATCH] C++20 constexpr lib part 2/3

2019-06-26 Thread Ed Smith-Rowland via gcc-patches

Implement C++20 p0879 - Constexpr for swap and swap related functions.

This is much smaller than the first but also basically marks swap and 
the algorithms that depend on swap as constexpr.


It is similarly tested on x86_64-linux:

$ make check -k -j4

$ make check RUNTESTFLAGS=--target_board=unix/-std=gnu++2a -k -j4

OK for trunk (after part 1 is in)?

Ed Smith-Rowland

2019-06-26  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0879 - Constexpr for swap and swap related functions.
* include/bits/algorithmfwd.h (__cpp_lib_constexpr_swap_algorithms):
New macro. (iter_swap, make_heap, next_permutation, partial_sort_copy,
pop_heap, prev_permutation, push_heap, reverse, rotate, sort_heap,
swap, swap_ranges, nth_element, partial_sort, sort): Add constexpr.
* include/bits/move.h (swap): Add constexpr.
* include/bits/stl_algo.h (__move_median_to_first, __reverse, reverse,
__gcd, __rotate, rotate, __partition, __heap_select,
__partial_sort_copy, partial_sort_copy, __unguarded_partition,
__unguarded_partition_pivot, __partial_sort, __introsort_loop, __sort,
__introselect, __chunk_insertion_sort, next_permutation,
prev_permutation, partition, partial_sort, nth_element, sort,
__iter_swap::iter_swap, iter_swap, swap_ranges): Add constexpr.
* include/bits/stl_algobase.h (__iter_swap::iter_swap, iter_swap,
swap_ranges): Add constexpr.
* include/bits/stl_heap.h (__push_heap, push_heap, __adjust_heap,
__pop_heap, pop_heap, __make_heap, make_heap, __sort_heap, sort_heap):
Add constexpr.
* include/std/type_traits (swap): Add constexpr.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Add constexpr.
* testsuite/25_algorithms/iter_swap/constexpr.cc: New test.
* testsuite/25_algorithms/make_heap/constexpr.cc: New test.
* testsuite/25_algorithms/next_permutation/constexpr.cc: New test.
* testsuite/25_algorithms/nth_element/constexpr.cc: New test.
* testsuite/25_algorithms/partial_sort/constexpr.cc: New test.
* testsuite/25_algorithms/partial_sort_copy/constexpr.cc: New test.
* testsuite/25_algorithms/partition/constexpr.cc: New test.
* testsuite/25_algorithms/pop_heap/constexpr.cc: New test.
* testsuite/25_algorithms/prev_permutation/constexpr.cc: New test.
* testsuite/25_algorithms/push_heap/constexpr.cc: New test.
* testsuite/25_algorithms/reverse/constexpr.cc: New test.
* testsuite/25_algorithms/rotate/constexpr.cc: New test.
* testsuite/25_algorithms/sort/constexpr.cc: New test.
* testsuite/25_algorithms/sort_heap/constexpr.cc: New test.
* testsuite/25_algorithms/swap/constexpr.cc: New test.
* testsuite/25_algorithms/swap_ranges/constexpr.cc: New test.

diff --git a/libstdc++-v3/include/bits/algorithmfwd.h 
b/libstdc++-v3/include/bits/algorithmfwd.h
index 14bdad9a61e..28b3388edaf 100644
--- a/libstdc++-v3/include/bits/algorithmfwd.h
+++ b/libstdc++-v3/include/bits/algorithmfwd.h
@@ -193,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus > 201703L
 #  define __cpp_lib_constexpr_algorithms 201711L
+#  define __cpp_lib_constexpr_swap_algorithms 201712L
 #endif
 
 #if __cplusplus >= 201103L
@@ -377,6 +378,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 iter_swap(_FIter1, _FIter2);
 
@@ -391,10 +393,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 lower_bound(_FIter, _FIter, const _Tp&, _Compare);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 make_heap(_RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 make_heap(_RAIter, _RAIter, _Compare);
 
@@ -478,10 +482,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // mismatch
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 next_permutation(_BIter, _BIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 next_permutation(_BIter, _BIter, _Compare);
 
@@ -496,10 +502,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // partial_sort
 
   template
+_GLIBCXX20_CONSTEXPR
 _RAIter
 partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 _RAIter
 partial_sort_copy(_IIter, _IIter, _RAIter, _RAIter, _Compare);
 
@@ -519,26 +527,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 pop_heap(_RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 pop_heap(_RAIter, _RAIter, _Compare);
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 prev_permutation(_BIter, _BIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 bool
 prev_permutation(_BIter, _BIter, _Compare);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 push_heap(_RAIter, _RAIter);
 
   template
+_GLIBCXX20_CONSTEXPR
 void
 push_heap(_RAIter, _RAIter, _Compare);
 

[PATCH 1/3] C++20 constexpr lib part 1/3

2019-06-26 Thread Ed Smith-Rowland via gcc-patches

Here is the first of three patches for C++20 constexpr library.

?? Implement C++20 p0202 - Add constexpr Modifiers to Functions in 
 and  Headers.

 ??Implement C++20 p1023 - constexpr comparison operators for std::array.

I believe I have answered peoples concerns with the last patch attempts 
[https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].


The patch is large because of test cases but really just boils down to 
adding constexpr for c++2a.


The patch passes testing for gnu++2a and pre-gnu++2a on x86_64-linux:

$ make check -k -j4

$ make check RUNTESTFLAGS=--target_board=unix/-std=gnu++2a -k -j4

OK for trunk?

Ed Smith-Rowland


2019-06-26  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, iter_swap, lower_bound,
none_of, partition_copy, partition_point, remove, remove_if,
remove_copy, remove_copy_if, replace_copy, replace_copy_if,
reverse_copy, rotate_copy, uunique, upper_bound, adjacent_find, count,
count_if, equal, find, find_first_of, find_if, for_each, generate,
generate_n, lexicographical_compare, merge, mismatch, replace,
replace_if, search, search_n, set_difference, set_intersection,
set_symmetric_difference, set_union, transform, unique_copy):
Mark constexpr.
* include/bits/cpp_type_traits.h (__miter_base): Mark constexpr.
* include/bits/predefined_ops.h (_Iter_less_val::operator(),
_Val_less_iter::operator(), _Iter_equal_to_iter::operator(),
_Iter_equal_to_val::operator(), _Iter_equals_val::operator()):
 Use const ref instead of ref arg;
(_Iter_less_val, __iter_less_val, _Val_less_iter, __val_less_iter,
__iter_equal_to_iter, __iter_equal_to_val, __iter_comp_val,
_Iter_comp_val, _Val_comp_iter, __val_comp_iter, __iter_equals_val,
_Iter_equals_iter, __iter_comp_iter, _Iter_pred, __pred_iter,
_Iter_comp_to_val, __iter_comp_val, _Iter_comp_to_iter,
__iter_comp_iter): Mark constexpr.
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of,
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
set_intersection, __set_difference, set_difference,
__set_symmetric_difference, set_symmetric_difference):  Mark constexpr.
* include/bits/stl_algobase.h (__memmove, __memcmp): New maybe constexpr
wrappers around __builtin_memmove and __builtin_memcmp
respectively;
(__niter_base, __niter_wrap, __copy_m, __copy_move_a, __copy_move_a2,
copy, move, __copy_move_b, __copy_move_backward_a,
__copy_move_backward_a2, copy_backward, move_backward, __fill_a, fill,
__fill_n_a, fill_n, equal, __lc_rai::__newlast1, __lc_rai::__cnd2,
__lexicographical_compare_impl, __lexicographical_compare,
__lexicographical_compare::__lc, __lexicographical_compare_aux,
__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
__mismatch, mismatch, __is_heap_until, __is_heap, is_heap_until,
is_heap): Mark constexpr.
* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
is_heap): Mark constexpr.
* include/bits/stl_iterator.h (__niter_base, __miter_base): Mark 
constexpr.
* include/std/array: Make comparison ops constexpr.
* include/std/utility: Make exchange constexpr.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
* testsuite/23_containers/array/tuple_interface/
tuple_element_neg.cc: Adjust.
* testsuite/20_util/ex

Re: Test for C++20 p0858 - ConstexprIterator requirements.

2019-06-10 Thread Ed Smith-Rowland via gcc-patches

On 6/10/19 2:43 AM, Ville Voutilainen wrote:

On Mon, 10 Jun 2019 at 02:53, Ed Smith-Rowland <3dw...@verizon.net> wrote:


Darn it, I had those constexpr lib patches in tree.
Attached are what I just committed to gcc-9 and passes there. Those
std::copy didn't really add anything anyway.

They added a test that *i++ = *j++ works, and that i != j works.


Ok,

Here is a version that adds back a hand written copy thing to test 
Ville's observation.


This is tested on a clean branch.

I would also like to add the same copy lines to the gcc-9 branch.

OK?

Ed


2019-06-11  Edward Smith-Rowland  <3dw...@verizon.net>

Test C++20 - p0858 ConstexprIterator requirements.
* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.

diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
index 24ab502372a..799fb0391f5 100644
--- 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
+++ 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
@@ -30,7 +30,11 @@ test()
   static_assert('W' == *(hw.cbegin() + 7));
 
   std::array a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
-  std::copy(hw.begin(), hw.end(), a2.begin());
+  auto hwi = hw.begin();
+  auto hwe = hw.end();
+  auto a2i = a2.begin();
+  while (hwi != hwe)
+*a2i++ = *hwi++;
 
   return *(hw.cbegin() + 3);
 }
diff --git 
a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc 
b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
index 88d69d2f8c7..4b5346631c9 100644
--- a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc
@@ -27,9 +27,13 @@ test()
   static_assert(1 == *a1.begin());
   auto n = a1[0] * a1[1]* a1[2];
   static_assert(1 == *a1.cbegin());
-
+ 
   std::array a2{{0, 0, 0}};
-  std::copy(a1.begin(), a1.end(), a2.begin());
+  auto a1i = a1.begin();
+  auto a1e = a1.end();
+  auto a2i = a2.begin();
+  while (a1i != a1e)
+*a2i++ = *a1i++;
 
   return n;
 }


Re: Test for C++20 p0858 - ConstexprIterator requirements.

2019-06-09 Thread Ed Smith-Rowland via gcc-patches

On 6/9/19 6:28 PM, Jonathan Wakely wrote:

On 10/06/19 00:03 +0200, Rainer Orth wrote:

Hi Ed,


I had supplied the option for gnu++2a by hand and they passed.?? They
were not UNSUPPORTED.

I just added the dg-options (at very top) and reran the testsuite
without fancy tricks (except for gnu++2a).

I also took out the #if __cplusplus.?? I was just playing around and
discovered that these pass in C++17 if you comment out the C++20
constexpr algos.

OK for trunk?


OK for trunk.

Committed 272084.


272085 actually ;-)?? Unfortunately, the new tests seem to FAIL (almost?)
everywhere:

+FAIL: 21_strings/basic_string_view/requirements/constexpr_iter.cc 
(test for excess errors)


Excess errors:
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:33: 
error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) 
[with _II = const char*; _OI = int*]'
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:41: 
error: 'constexpr char test()' called in a constant expression


+FAIL: 23_containers/array/requirements/constexpr_iter.cc (test for 
excess errors)


/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:32: 
error: call to non-'constexpr' function '_OI std::copy(_II, _II, _OI) 
[with _II = const int*; _OI = int*]'
/vol/gcc/src/hg/trunk/local/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc:40: 
error: 'constexpr int test()' called in a constant expression


I'm seeing those on i386-pc-solaris2.11 and sparc-sun-solaris2.11, and
there are gcc-testresults reports on aarch64-unknown-linux-gnu,
i686-pc-linux-gnu, powerpc64le-unknown-linux-gnu, and
x86_64-pc-linux-gnu, among others.


Presumably because std::copy isn't actually constexpr yet.

Ed, do you have uncommitted local changes that allow this test to
pass? Because I don't see how it can pass otherwise.


Darn it, I had those constexpr lib patches in tree.

Attached are what I just committed to gcc-9 and passes there. Those 
std::copy didn't really add anything anyway.


Note to self - no matter how small work on a separate branch.

I'm testing on a new clean branch unless someone beats me to it.

Sorry for all the noise.

Ed


Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(revision 272098)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(working copy)
@@ -29,9 +29,6 @@
   auto ch = hw[4];
   static_assert('W' == *(hw.cbegin() + 7));
 
-  std::array a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
-  std::copy(hw.begin(), hw.end(), a2.begin());
-
   return *(hw.cbegin() + 3);
 }
 
Index: testsuite/23_containers/array/requirements/constexpr_iter.cc
===
--- testsuite/23_containers/array/requirements/constexpr_iter.cc
(revision 272098)
+++ testsuite/23_containers/array/requirements/constexpr_iter.cc
(working copy)
@@ -28,9 +28,6 @@
   auto n = a1[0] * a1[1]* a1[2];
   static_assert(1 == *a1.cbegin());
 
-  std::array a2{{0, 0, 0}};
-  std::copy(a1.begin(), a1.end(), a2.begin());
-
   return n;
 }
 


Re: Test for C++20 p0858 - ConstexprIterator requirements.

2019-06-09 Thread Ed Smith-Rowland via gcc-patches

On 6/8/19 4:28 PM, Jonathan Wakely wrote:

On 08/06/19 12:05 -0400, Ed Smith-Rowland wrote:

On 6/7/19 11:42 AM, Jonathan Wakely wrote:

On 01/06/19 15:40 -0400, Ed Smith-Rowland via libstdc++ wrote:

On 6/1/19 2:42 PM, Ville Voutilainen wrote:
On Sat, 1 Jun 2019 at 21:09, Ed Smith-Rowland <3dw...@verizon.net> 
wrote:

On 5/31/19 6:29 PM, Ville Voutilainen wrote:

On Sat, 1 Jun 2019 at 01:24, Ed Smith-Rowland via libstdc++
 wrote:

Greetings,

Iterators for  and  are usabe in a 
constexpr context

since C++2017.

This just adds a compile test to make sure and check a box for 
C++20

p0858 - ConstexprIterator requirements.

Those tests don't use the iterators in a constexpr context. To do
that, maybe do those std::copy operations
in a constexpr function and then initialize a constexpr variable 
with

the result of a call to that function?

Thanks Ville,

I had completely forgotten to make these test functions constexpr 
- FIXED.

.but that doesn't enforce a constexpr context. If you add another
function that calls these functions
and initializes a constexpr variable, then we have the enforcement I
seek. Such as

void test2()
{
?? constexpr char x = test();
}


Ok, third time's a charm.

I was brain dead about the constexpr patch.?? I'm now setting a 
constexpr variable from test() in a caller.


But static_assert is a constexpr context no?

Ed





2019-06-03?? Edward Smith-Rowland <3dw...@verizon.net>

Test for C++20 p0858 - ConstexprIterator requirements.
* 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:

New test.
* 
testsuite/23_containers/array/requirements/constexpr_iter.cc:

New test.



Index: 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc

===
--- 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc 
(nonexistent)
+++ 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc 
(working copy)

@@ -0,0 +1,43 @@
+// { dg-do compile { target c++2a } }


Please check the testsuite/libstdc++.log or testsuite/libstdc++.sum
files for the new tests. I expect they are both UNSUPPORTED.

That's because you've given a target c++2a which means they won't be
run unless a suitable -std option is given. And you haven't given one.

You need to add { dg-options "-std=gnu++2a" } before the dg-do line.

Also if the tests are restricted to C++2a then there's no point having
the #if __cplusplus > 201703L check, because that will never be false.

I had supplied the option for gnu++2a by hand and they passed.?? They 
were not UNSUPPORTED.


I just added the dg-options (at very top) and reran the testsuite 
without fancy tricks (except for gnu++2a).


I also took out the #if __cplusplus.?? I was just playing around and 
discovered that these pass in C++17 if you comment out the C++20 
constexpr algos.


OK for trunk?


OK for trunk.

Committed 272084.


Also, we could declare victory for this for gcc-9.?? May I backport 
after this is in?


Yes, these tests are also OK to backport to gcc-9-branch (assuming
they pass on the branch, which I agree they should do).

Thanks!

The backport is the same less the calls to std::copy. CL and patch 
attached. Committed 272097.


Ed

2019-06-09  Edward Smith-Rowland  <3dw...@verizon.net>

Test for C++20 p0858 - ConstexprIterator requirements.
* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.

Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(nonexistent)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(working copy)
@@ -0,0 +1,39 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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/>.
+
+#include 
+#include 
+
+constexpr char
+test()
+{
+  constexpr std::string_view hw("Hello, World!");
+  static_assert('H'

Re: Test for C++20 p0858 - ConstexprIterator requirements.

2019-06-08 Thread Ed Smith-Rowland via gcc-patches

On 6/7/19 11:42 AM, Jonathan Wakely wrote:

On 01/06/19 15:40 -0400, Ed Smith-Rowland via libstdc++ wrote:

On 6/1/19 2:42 PM, Ville Voutilainen wrote:
On Sat, 1 Jun 2019 at 21:09, Ed Smith-Rowland <3dw...@verizon.net> 
wrote:

On 5/31/19 6:29 PM, Ville Voutilainen wrote:

On Sat, 1 Jun 2019 at 01:24, Ed Smith-Rowland via libstdc++
 wrote:

Greetings,

Iterators for  and  are usabe in a constexpr 
context

since C++2017.

This just adds a compile test to make sure and check a box for C++20
p0858 - ConstexprIterator requirements.

Those tests don't use the iterators in a constexpr context. To do
that, maybe do those std::copy operations
in a constexpr function and then initialize a constexpr variable with
the result of a call to that function?

Thanks Ville,

I had completely forgotten to make these test functions constexpr - 
FIXED.

.but that doesn't enforce a constexpr context. If you add another
function that calls these functions
and initializes a constexpr variable, then we have the enforcement I
seek. Such as

void test2()
{
?? constexpr char x = test();
}


Ok, third time's a charm.

I was brain dead about the constexpr patch.?? I'm now setting a 
constexpr variable from test() in a caller.


But static_assert is a constexpr context no?

Ed





2019-06-03?? Edward Smith-Rowland <3dw...@verizon.net>

Test for C++20 p0858 - ConstexprIterator requirements.
* 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:

New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.



Index: 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc

===
--- 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc 
(nonexistent)
+++ 
testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc 
(working copy)

@@ -0,0 +1,43 @@
+// { dg-do compile { target c++2a } }


Please check the testsuite/libstdc++.log or testsuite/libstdc++.sum
files for the new tests. I expect they are both UNSUPPORTED.

That's because you've given a target c++2a which means they won't be
run unless a suitable -std option is given. And you haven't given one.

You need to add { dg-options "-std=gnu++2a" } before the dg-do line.

Also if the tests are restricted to C++2a then there's no point having
the #if __cplusplus > 201703L check, because that will never be false.

I had supplied the option for gnu++2a by hand and they passed.?? They 
were not UNSUPPORTED.


I just added the dg-options (at very top) and reran the testsuite 
without fancy tricks (except for gnu++2a).


I also took out the #if __cplusplus.?? I was just playing around and 
discovered that these pass in C++17 if you comment out the C++20 
constexpr algos.


OK for trunk?

Also, we could declare victory for this for gcc-9.?? May I backport after 
this is in?


Ed


2019-06-10  Edward Smith-Rowland  <3dw...@verizon.net>

Test for C++20 p0858 - ConstexprIterator requirements.
* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.

Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(nonexistent)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(working copy)
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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/>.
+
+#include 
+#include 
+
+constexpr char
+test()
+{
+  constexpr std::string_view hw("Hello, World!");
+  static_assert('H' == *hw.begin());
+  auto ch = hw[4];
+  static_assert('W' == *(hw.cbegin() + 7));
+
+  std::array a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+
+  return *(hw.cbegin() + 3);
+}
+
+void
+run_test()
+{
+  constexpr char ch = test();
+}
Index: testsuite/23_containers/array/requirements/constexpr_iter.cc

Re: Test for C++20 p0858 - ConstexprIterator requirements.

2019-06-01 Thread Ed Smith-Rowland via gcc-patches

On 6/1/19 2:42 PM, Ville Voutilainen wrote:

On Sat, 1 Jun 2019 at 21:09, Ed Smith-Rowland <3dw...@verizon.net> wrote:

On 5/31/19 6:29 PM, Ville Voutilainen wrote:

On Sat, 1 Jun 2019 at 01:24, Ed Smith-Rowland via libstdc++
 wrote:

Greetings,

Iterators for  and  are usabe in a constexpr context
since C++2017.

This just adds a compile test to make sure and check a box for C++20
p0858 - ConstexprIterator requirements.

Those tests don't use the iterators in a constexpr context. To do
that, maybe do those std::copy operations
in a constexpr function and then initialize a constexpr variable with
the result of a call to that function?

Thanks Ville,

I had completely forgotten to make these test functions constexpr - FIXED.

.but that doesn't enforce a constexpr context. If you add another
function that calls these functions
and initializes a constexpr variable, then we have the enforcement I
seek. Such as

void test2()
{
 constexpr char x = test();
}


Ok, third time's a charm.

I was brain dead about the constexpr patch.?? I'm now setting a constexpr 
variable from test() in a caller.


But static_assert is a constexpr context no?

Ed


2019-06-03  Edward Smith-Rowland  <3dw...@verizon.net>

Test for C++20 p0858 - ConstexprIterator requirements.
* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.

Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(nonexistent)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(working copy)
@@ -0,0 +1,43 @@
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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/>.
+
+#include 
+#include 
+
+constexpr char
+test()
+{
+  constexpr std::string_view hw("Hello, World!");
+  static_assert('H' == *hw.begin());
+  auto ch = hw[4];
+  static_assert('W' == *(hw.cbegin() + 7));
+
+#if __cplusplus > 201703L
+  std::array a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+#endif
+
+  return *(hw.cbegin() + 3);
+}
+
+void
+run_test()
+{
+  constexpr char ch = test();
+}
Index: testsuite/23_containers/array/requirements/constexpr_iter.cc
===
--- testsuite/23_containers/array/requirements/constexpr_iter.cc
(nonexistent)
+++ testsuite/23_containers/array/requirements/constexpr_iter.cc
(working copy)
@@ -0,0 +1,42 @@
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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/>.
+
+#include 
+
+constexpr int
+test()
+{
+  constexpr std::array a1{{1, 2, 3}};
+  static_assert(1 == *a1.begin());
+  auto n = a1[0] * a1[1]* a1[2];
+  static_assert(1 == *a1.cbegin());
+
+#if __cplusplus > 201703L
+  std::array a2{{0, 0, 0}};
+  std::copy(a1.begin(), a1.end(), a2.begin());
+#endif
+
+  return n;
+}
+
+void
+run_test()
+{
+  constexpr int n = test();
+}


Re: Test for C++20 p0858 - ConstexprIterator requirements.

2019-06-01 Thread Ed Smith-Rowland via gcc-patches

On 5/31/19 6:29 PM, Ville Voutilainen wrote:

On Sat, 1 Jun 2019 at 01:24, Ed Smith-Rowland via libstdc++
 wrote:

Greetings,

Iterators for  and  are usabe in a constexpr context
since C++2017.

This just adds a compile test to make sure and check a box for C++20
p0858 - ConstexprIterator requirements.


Those tests don't use the iterators in a constexpr context. To do
that, maybe do those std::copy operations
in a constexpr function and then initialize a constexpr variable with
the result of a call to that function?


Thanks Ville,

I had completely forgotten to make these test functions constexpr - FIXED.

Also, instead of bool variables I put the checks in static_asserts.

I return functions of (derefed) iterators.

I made it so we could run these at C++17 if we want to with '#if 
__cplusplus == 201703L' the algorithm usage for C++20 only.?? This wasn't 
a DR though.


Anyway, that should do it.

Built and tested clean on x86_64-linux. Ok?

Ed


2019-06-03  Edward Smith-Rowland  <3dw...@verizon.net>

Test for C++20 p0858 - ConstexprIterator requirements.
* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.

Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(nonexistent)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(working copy)
@@ -0,0 +1,37 @@
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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/>.
+
+#include 
+#include 
+
+constexpr char
+test()
+{
+  constexpr std::string_view hw("Hello, World!");
+  static_assert('H' == *hw.begin());
+  auto ch = hw[4];
+  static_assert('W' == *(hw.cbegin() + 7));
+
+#if __cplusplus > 201703L
+  std::array a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+#endif
+
+  return *(hw.cbegin() + 3);
+}
Index: testsuite/23_containers/array/requirements/constexpr_iter.cc
===
--- testsuite/23_containers/array/requirements/constexpr_iter.cc
(nonexistent)
+++ testsuite/23_containers/array/requirements/constexpr_iter.cc
(working copy)
@@ -0,0 +1,36 @@
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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/>.
+
+#include 
+
+constexpr int
+test()
+{
+  constexpr std::array a1{{1, 2, 3}};
+  static_assert(1 == *a1.begin());
+  auto n = a1[0] * a1[1]* a1[2];
+  static_assert(1 == *a1.cbegin());
+
+#if __cplusplus > 201703L
+  std::array a2{{0, 0, 0}};
+  std::copy(a1.begin(), a1.end(), a2.begin());
+#endif
+
+  return n;
+}


Test for C++20 p0858 - ConstexprIterator requirements.

2019-05-31 Thread Ed Smith-Rowland via gcc-patches

Greetings,

Iterators for  and  are usabe in a constexpr context 
since C++2017.


This just adds a compile test to make sure and check a box for C++20 
p0858 - ConstexprIterator requirements.


Ed


2019-06-03  Edward Smith-Rowland  <3dw...@verizon.net>

Test for C++20 p0858 - ConstexprIterator requirements.
* testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc:
New test.
* testsuite/23_containers/array/requirements/constexpr_iter.cc:
New test.

Index: testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc
===
--- testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(nonexistent)
+++ testsuite/21_strings/basic_string_view/requirements/constexpr_iter.cc   
(working copy)
@@ -0,0 +1,33 @@
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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
+// .
+
+#include 
+#include 
+
+void
+test()
+{
+  constexpr std::string_view hw("Hello, World!");
+  bool ok = 'H' == *hw.begin();
+  auto ch = hw[4];
+  bool cok = 'W' == *(hw.cbegin() + 7);
+
+  std::array a2{{0,0,0,0,0,0,0,0,0,0,0,0,0}};
+  std::copy(hw.begin(), hw.end(), a2.begin());
+}
Index: testsuite/23_containers/array/requirements/constexpr_iter.cc
===
--- testsuite/23_containers/array/requirements/constexpr_iter.cc
(nonexistent)
+++ testsuite/23_containers/array/requirements/constexpr_iter.cc
(working copy)
@@ -0,0 +1,32 @@
+// { dg-do compile { target c++2a } }
+//
+// Copyright (C) 2019 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
+// .
+
+#include 
+
+void
+test()
+{
+  constexpr std::array a1{{1, 2, 3}};
+  bool ok = 1 == *a1.begin();
+  auto n = a1[0] * a1[1]* a1[2];
+  bool cok = 1 == *a1.cbegin();
+
+  std::array a2{{0, 0, 0}};
+  std::copy(a1.begin(), a1.end(), a2.begin());
+}


Re: [PATCH,libstdc++] C++-20 costexpr and

2019-05-30 Thread Ed Smith-Rowland via gcc-patches

On 5/30/19 5:05 PM, Ed Smith-Rowland via libstdc++ wrote:

Greetings,

I was not quite able to finish this in for gcc9 but here is the patch 
for:


?? Implement C++20 p0202 - Add Constexpr Modifiers to Functions
 ??in  and  Headers.
 ??Implement C++20 p1023 - constexpr comparison operators for 
std::array.


I believe I have answered peoples concerns with the last patch 
attempts [https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].


The patch is large because of test cases but really just boils down to 
adding constexpr for c++2a.


The patch passes for gnu++2a and pre-gnu++2a on x86_64-linux.

OK for trunk?

Ed Smith-Rowland


Actually, I got 6 excess error fails in C++20 (I keep forgetting to 
actually test that option, sorry):


FAIL: 25_algorithms/copy/58982.cc (test for excess errors)
FAIL: 25_algorithms/copy/move_iterators/69478.cc (test for excess errors)
FAIL: 25_algorithms/copy_backward/move_iterators/69478.cc (test for 
excess errors)

FAIL: 25_algorithms/copy_n/58982.cc (test for excess errors)
FAIL: 25_algorithms/move/69478.cc (test for excess errors)
FAIL: 25_algorithms/move_backward/69478.cc (test for excess errors)

These excess errors are all 'error: use of deleted function' for copy 
assignments - which is true.?? I just had the wrong prune string. My 
deja-gnu is wobbly.


The guts of the previous patch are still unchanged but here is a new 
patch with the fixed testcases.


This passes C++20 and earlier.

Sorry for the noise.

OK?

Ed


2019-05-31  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, fill_n, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, lower_bound, none_of,
partition_copy, partition_point, remove, remove_if, remove_copy,
remove_copy_if, replace_copy, replace_copy_if, reverse_copy,
rotate_copy, unique, upper_bound, adjacent_find, count, count_if, equal,
find, find_first_of, find_if, for_each, generate, generate_n,
lexicographical_compare, merge, mismatch, replace, replace_if, search,
search_n, set_difference, set_intersection, set_symmetric_difference,
set_union, transform, unique_copy): Mark constexpr.
Make versions of operator() const.
* include/bits/cpp_type_traits.h (__miter_base): Make constexpr.
* include/bits/predefined_ops.h (_Iter_less_val, __iter_comp_val,
_Val_less_iter, __val_less_iter, __val_comp_iter, _Iter_equal_to_iter,
__iter_equal_to_iter, _Iter_equal_to_val, __iter_equal_to_val,
_Iter_comp_val, __iter_comp_val, _Val_comp_iter, __val_comp_iter,
_Iter_equals_val, __iter_equals_val, _Iter_equals_iter,
__iter_comp_iter, __pred_iter, __iter_comp_val, __negate): Constexpr
ctors. Add const operator().
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
set_intersection, __set_difference, set_difference,
__set_symmetric_difference, set_symmetric_difference): Constexpr.
* include/bits/stl_algobase.h (__niter_base, __niter_wrap, __copy_m,
__copy_move_a, copy, move, __copy_move_backward::__copy_move_b,
__copy_move_backward_a, __copy_move_backward_a2, copy_backward,
move_backward, fill, __fill_a, __fill_n_a, fill_n, __equal::equal,
__equal_aux, __newlast1, __cnd2, __newlast1, __cnd2,
__lexicographical_compare_impl, __lexicographical_compare::__lc,
__lexicographical_compare, __lexicographical_compare_aux,
__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
__mismatch, mi

[PATCH,libstdc++] C++-20 costexpr and

2019-05-30 Thread Ed Smith-Rowland via gcc-patches

Greetings,

I was not quite able to finish this in for gcc9 but here is the patch for:

?? Implement C++20 p0202 - Add Constexpr Modifiers to Functions
 ??in  and  Headers.
 ??Implement C++20 p1023 - constexpr comparison operators for std::array.

I believe I have answered peoples concerns with the last patch attempts 
[https://gcc.gnu.org/ml/libstdc++/2019-03/msg00132.html].


The patch is large because of test cases but really just boils down to 
adding constexpr for c++2a.


The patch passes for gnu++2a and pre-gnu++2a on x86_64-linux.

OK for trunk?

Ed Smith-Rowland


2019-05-31  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, fill_n, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, lower_bound, none_of,
partition_copy, partition_point, remove, remove_if, remove_copy,
remove_copy_if, replace_copy, replace_copy_if, reverse_copy,
rotate_copy, unique, upper_bound, adjacent_find, count, count_if, equal,
find, find_first_of, find_if, for_each, generate, generate_n,
lexicographical_compare, merge, mismatch, replace, replace_if, search,
search_n, set_difference, set_intersection, set_symmetric_difference,
set_union, transform, unique_copy): Mark constexpr.
Make versions of operator() const.
* include/bits/cpp_type_traits.h (__miter_base): Make constexpr.
* include/bits/predefined_ops.h (_Iter_less_val, __iter_comp_val,
_Val_less_iter, __val_less_iter, __val_comp_iter, _Iter_equal_to_iter,
__iter_equal_to_iter, _Iter_equal_to_val, __iter_equal_to_val,
_Iter_comp_val, __iter_comp_val, _Val_comp_iter, __val_comp_iter,
_Iter_equals_val, __iter_equals_val, _Iter_equals_iter,
__iter_comp_iter, __pred_iter, __iter_comp_val, __negate): Constexpr
ctors. Add const operator().
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
set_intersection, __set_difference, set_difference,
__set_symmetric_difference, set_symmetric_difference): Constexpr.
* include/bits/stl_algobase.h (__niter_base, __niter_wrap, __copy_m,
__copy_move_a, copy, move, __copy_move_backward::__copy_move_b,
__copy_move_backward_a, __copy_move_backward_a2, copy_backward,
move_backward, fill, __fill_a, __fill_n_a, fill_n, __equal::equal,
__equal_aux, __newlast1, __cnd2, __newlast1, __cnd2,
__lexicographical_compare_impl, __lexicographical_compare::__lc,
__lexicographical_compare, __lexicographical_compare_aux,
__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
__mismatch, mismatch): Constexpr.
(__memmove, __memcmp): New constexpr wrappers.
* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
is_heap): Constexpr.
* include/bits/stl_iterator.h (__niter_base, __miter_base): Constexpr.
* include/std/array: Make comparison ops constexpr.
* include/std/utility: Make exchange constexpr.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
* testsuite/23_containers/array/tuple_interface/
tuple_element_neg.cc: Adjust.
* testsuite/25_algorithms/copy_n/58982.cc: Adjust error scan.
Prune "deleted".
* testsuite/25_algorithms/copy/58982.cc: Adjust error scan.
Prune "deleted".
* testsuite/25_algorithms/copy/move_iterators/69478.cc: Prune "deleted".
* testsuite/25_algorithms/copy_backward/move_iterat

Implement numeric_limits<__float128>.

2019-05-10 Thread Ed Smith-Rowland via gcc-patches

Greetings,

I know people are mostly looking at release branch work but I'd like to 
post this.  Other projects like mppp and boost use our __float128 with 
C++.  I use it for specfun testing and various other projects. I'd like 
to offer a series of patches to enable this support straight from 
libstdc++.  This is the first patch. Next will be  and then 
 a bit later.


It's pretty straightforward but others might have tips on configuration 
(and anything else ;-)).  Built and tested of x86_64-linux.


Ok?

Ed


2019-05-11  Ed Smith-Rowland  <3dw...@verizon.net>

Implement numeric_limits<__float128>.
* include/std/limits: Copy limit macros from quadmath.h;
(__glibcxx_float128_has_denorm_loss, __glibcxx_float128_traps,
__glibcxx_float128_tinyness_before): New macros (set to false);
(numeric_limits<__float128>): New specialization.
* : Add __float128 test guarded by _GLIBCXX_USE_FLOAT128.
* : testsuite/18_support/numeric_limits/denorm_min.cc: Add __float128
test guarded by _GLIBCXX_USE_FLOAT128.
* : testsuite/18_support/numeric_limits/dr559.cc: Same.
* : testsuite/18_support/numeric_limits/epsilon.cc: Same.
* : testsuite/18_support/numeric_limits/infinity.cc: Same.
* : testsuite/18_support/numeric_limits/is_iec559.cc: Same.
* : testsuite/18_support/numeric_limits/lowest.cc: Same.
* : testsuite/18_support/numeric_limits/max_digits10.cc: Same.
* : testsuite/18_support/numeric_limits/min_max.cc: Same.
* : testsuite/18_support/numeric_limits/quiet_NaN.cc: Same.

Index: include/std/limits
===
--- include/std/limits  (revision 271076)
+++ include/std/limits  (working copy)
@@ -41,6 +41,19 @@
 
 #include 
 
+#if defined(_GLIBCXX_USE_FLOAT128) && !defined(__STRICT_ANSI__)
+#  define FLT128_MAX 1.18973149535723176508575932662800702e4932Q
+#  define FLT128_MIN 3.36210314311209350626267781732175260e-4932Q
+#  define FLT128_EPSILON 1.92592994438723585305597794258492732e-34Q
+#  define FLT128_DENORM_MIN 6.475175119438025110924438958227646552e-4966Q
+#  define FLT128_MANT_DIG 113
+#  define FLT128_MIN_EXP (-16381)
+#  define FLT128_MAX_EXP 16384
+#  define FLT128_DIG 33
+#  define FLT128_MIN_10_EXP (-4931)
+#  define FLT128_MAX_10_EXP 4932
+#endif
+
 //
 // The numeric_limits<> traits document implementation-defined aspects
 // of fundamental arithmetic data types (integers and floating points).
@@ -123,6 +136,24 @@
 #  define __glibcxx_long_double_tinyness_before false
 #endif
 
+#if defined(_GLIBCXX_USE_FLOAT128) && !defined(__STRICT_ANSI__)
+
+// __float128
+
+// Default values.  Should be overridden in configuration files if necessary.
+
+#  ifndef __glibcxx_float128_has_denorm_loss
+#define __glibcxx_float128_has_denorm_loss false
+#  endif
+#  ifndef __glibcxx_float128_traps
+#define __glibcxx_float128_traps false
+#  endif
+#  ifndef __glibcxx_float128_tinyness_before
+#define __glibcxx_float128_tinyness_before false
+#  endif
+
+#  endif // _GLIBCXX_USE_FLOAT128
+
 // You should not need to define any macros below this point.
 
 #define __glibcxx_signed_b(T,B)((T)(-1) < 0)
@@ -1880,6 +1911,85 @@
 #undef __glibcxx_long_double_traps
 #undef __glibcxx_long_double_tinyness_before
 
+#if defined(_GLIBCXX_USE_FLOAT128) && !defined(__STRICT_ANSI__)
+
+  /// numeric_limits<__float128> specialization.
+  template<>
+struct numeric_limits<__float128>
+{
+  static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true;
+
+  static _GLIBCXX_CONSTEXPR __float128
+  min() _GLIBCXX_USE_NOEXCEPT { return FLT128_MIN; }
+
+  static _GLIBCXX_CONSTEXPR __float128
+  max() _GLIBCXX_USE_NOEXCEPT { return FLT128_MAX; }
+
+#if __cplusplus >= 201103L
+  static _GLIBCXX_CONSTEXPR __float128
+  lowest() _GLIBCXX_USE_NOEXCEPT { return -FLT128_MAX; }
+#endif
+
+  static _GLIBCXX_USE_CONSTEXPR int digits = FLT128_MANT_DIG;
+  static _GLIBCXX_USE_CONSTEXPR int digits10 = FLT128_DIG;
+#if __cplusplus >= 201103L
+  static _GLIBCXX_USE_CONSTEXPR int max_digits10
+= __glibcxx_max_digits10 (FLT128_MANT_DIG);
+#endif
+  static _GLIBCXX_USE_CONSTEXPR bool is_signed = true;
+  static _GLIBCXX_USE_CONSTEXPR bool is_integer = false;
+  static _GLIBCXX_USE_CONSTEXPR bool is_exact = false;
+  static _GLIBCXX_USE_CONSTEXPR int radix = __FLT_RADIX__;
+
+  static _GLIBCXX_CONSTEXPR __float128
+  epsilon() _GLIBCXX_USE_NOEXCEPT { return FLT128_EPSILON; }
+
+  static _GLIBCXX_CONSTEXPR __float128
+  round_error() _GLIBCXX_USE_NOEXCEPT { return 0.5Q; }
+
+  static _GLIBCXX_USE_CONSTEXPR int min_exponent = FLT128_MIN_EXP;
+  static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = FLT128_MIN_10_EXP;
+  static _GLIBCXX_USE_CONSTEXPR int max_exponent = FLT128_MAX_EXP;
+  static _GL

Re: Implement C++20 constexpr , , and

2019-03-29 Thread Ed Smith-Rowland via gcc-patches

On 3/29/19 12:39 PM, Jakub Jelinek wrote:

On Fri, Mar 29, 2019 at 12:02:48PM -0400, Ed Smith-Rowland wrote:

This differs from the previous patch in actually testing constexpr :-\ and
in the addition of wrappers for __builtin_memmove and __builtin_memcmp that
supply constexpr branches if C++20 and is_constant_evaluated().

+void*
+__memmove(_Tp* __dst, const _Tp* __src, ptrdiff_t __num)
+{
+#if __cplusplus > 201703L
+  if (is_constant_evaluated())
+   {
+ for(; __num > 0; --__num)
+   {
+ *__dst = *__src;
+ ++__src;
+ ++__dst;
+   }
+ return __dst;
+   }
+  else if (__num)
+#endif
+   return __builtin_memmove(__dst, __src, sizeof(_Tp) * abs(__num));
+  return __dst;
..
  const ptrdiff_t _Num = __last - __first;
if (_Num)
-   __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
+   __memmove(__result, __first, _Num);
..
  const ptrdiff_t _Num = __last - __first;
if (_Num)
-   __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
+   __memmove(__result - _Num, __first, _Num);

Why the abs in there, that is something that wasn't previously there and
if the compiler doesn't figure out that __last >= __first, it would mean
larger emitted code for the non-constexpr case.  As memmove argument is
size_t, wouldn't it be better to make __num just size_t and remove this abs?
Also, wouldn't it be better to have on the other side the __num == 0
handling inside of __memmove, you already have it there for C++2a, but not
for older.  You could then drop the if (_Num) guards around __memmove.

memmove needs to be able to work with __last < __first also.

I don't get it, you are replacing calls with __builtin_memmove with
__memmove, and the __builtin_memmove calls didn't do anything like that,
the last argument is size_t and didn't use any abs.  So are you saying you
see crashes with the current code (when not in constexpr contexts) that your
patch fixes?

Jakub

If std::copy is intended to work with first < last then yes. OTOH, the 
copy_move is just an impl detail for speed.


The std doesn't say that first >= last as a precondition but has 
sentences like:


"For each non-negative integer n < (last - first), performs *(result + 
n) = *(first + n)."


If this fixes a bug then I should make a pug report, a separate patch, 
and probably backport it.


I also took out the else if (__num) in the __memmove since this check is 
done at both call sites.


I made __memmove and __memcmp inline so that, certainly for C++ < 20 
these don't pessimize.


Retesting.

Ed


int
main()
{
  float arr[1000];
  float brr[1000];
  std::copy(arr + 500, arr, brr + 500);
}



Re: Implement C++20 constexpr , , and

2019-03-29 Thread Ed Smith-Rowland via gcc-patches

On 3/29/19 11:12 AM, Jakub Jelinek wrote:

On Fri, Mar 29, 2019 at 11:07:53AM -0400, Jason Merrill wrote:

On Tue, Mar 19, 2019 at 4:57 PM Ed Smith-Rowland via gcc-patches
 wrote:

On 3/18/19 6:18 PM, Jonathan Wakely wrote:

On 17/03/19 22:54 -0400, Ed Smith-Rowland via libstdc++ wrote:
I'm very surprised that none of the algos that dispatch to
__builtin_memove need changes, because those optimizations won't work
in constant expressions. I would expect to have to use
std::is_constant_evaluated to disable the optimizations when used in
constant expressions.


As am I. As I mentioned on IRC I could roll a constexpr memmove.

I was wondering if somehow I'm not checking what I think I'm checking
(but I don't see how.)

I wonder if the builtins are handled differently somehow by the front
end.  I'm still not sure why __builtin_memcmp is OK for array == array
but not array != array.  In that case I just do element by element
compare for constexpr now anyway.

Is there a PR about making these builtins work in constexpr?

Yes, PR80265.

Jakub

I see what you did there ;-) I could make my patch use the same idiom as 
what you have in the char_traits patch if folks would prefer.


BTW, what does

(void) __s;

do?

In other news, assuming that it's official there was constexpr in 
char_traits in some paper.  I was going to try that but it looks like 
you were starting.


Ed



Re: Implement C++20 constexpr , , and

2019-03-29 Thread Ed Smith-Rowland via gcc-patches

On 3/29/19 9:23 AM, Jakub Jelinek wrote:

On Fri, Mar 29, 2019 at 09:10:26AM -0400, Ed Smith-Rowland via gcc-patches 
wrote:

Greetings,

This patch implements C++20 constexpr for , , .

It's a large patch but only affects C++20 and the volume is mostly test
cases.

This differs from the previous patch in actually testing constexpr :-\ and
in the addition of wrappers for __builtin_memmove and __builtin_memcmp that
supply constexpr branches if C++20 and is_constant_evaluated().

+void*
+__memmove(_Tp* __dst, const _Tp* __src, ptrdiff_t __num)
+{
+#if __cplusplus > 201703L
+  if (is_constant_evaluated())
+   {
+ for(; __num > 0; --__num)
+   {
+ *__dst = *__src;
+ ++__src;
+ ++__dst;
+   }
+ return __dst;
+   }
+  else if (__num)
+#endif
+   return __builtin_memmove(__dst, __src, sizeof(_Tp) * abs(__num));
+  return __dst;
..
  const ptrdiff_t _Num = __last - __first;
   if (_Num)
-   __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
+   __memmove(__result, __first, _Num);
..
  const ptrdiff_t _Num = __last - __first;
   if (_Num)
-   __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
+   __memmove(__result - _Num, __first, _Num);

Why the abs in there, that is something that wasn't previously there and
if the compiler doesn't figure out that __last >= __first, it would mean
larger emitted code for the non-constexpr case.  As memmove argument is
size_t, wouldn't it be better to make __num just size_t and remove this abs?
Also, wouldn't it be better to have on the other side the __num == 0
handling inside of __memmove, you already have it there for C++2a, but not
for older.  You could then drop the if (_Num) guards around __memmove.


memmove needs to be able to work with __last < __first also.

I was getting negative __num and when passed to __builtin_memmove which 
takes size_t got blowups.


I'm not sure why it worked before. __builtin_memmove will work with 
__last < __first and sensible positive __num.


When I tried to do what __builtin_memmove or ::memmove must do with 
unsigned num I would need to branch on __last < __first


and copy backwards.  But pointer comparisons were getting caught as 
non-constexpr.


I'll look at the __num==0 (noop) testing.



Also, shouldn't the is_constant_evaluated() calls be guarded with
_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED ?  Without that it won't be
defined...


I am trying for a C++20-only patch (hoping to get it in for 9) so I used 
the library function and tested __cplusplus > 201703L.


We could do _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED and then we 
could use these for lower version. Maybe stage 1?




Jakub





Re: Implement C++20 constexpr , , and

2019-03-29 Thread Ed Smith-Rowland via gcc-patches

Greetings,

This patch implements C++20 constexpr for , , .

It's a large patch but only affects C++20 and the volume is mostly test 
cases.


This differs from the previous patch in actually testing constexpr :-\ 
and in the addition of wrappers for __builtin_memmove and 
__builtin_memcmp that supply constexpr branches if C++20 and 
is_constant_evaluated().


This builds and tests clean on x86_64-linux.

OK?


2019-03-29  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, fill_n, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, lower_bound, none_of,
partition_copy, partition_point, remove, remove_if, remove_copy,
remove_copy_if, replace_copy, replace_copy_if, reverse_copy,
rotate_copy, unique, upper_bound, adjacent_find, count, count_if, equal,
find, find_first_of, find_if, for_each, generate, generate_n,
lexicographical_compare, merge, mismatch, replace, replace_if, search,
search_n, set_difference, set_intersection, set_symmetric_difference,
set_union, transform, unique_copy): Mark constexpr.
Make versions of operator() const.
* include/bits/cpp_type_traits.h (__miter_base): Make constexpr.
* include/bits/predefined_ops.h (_Iter_less_val, __iter_comp_val,
_Val_less_iter, __val_less_iter, __val_comp_iter, _Iter_equal_to_iter,
__iter_equal_to_iter, _Iter_equal_to_val, __iter_equal_to_val,
_Iter_comp_val, __iter_comp_val, _Val_comp_iter, __val_comp_iter,
_Iter_equals_val, __iter_equals_val, _Iter_equals_iter,
__iter_comp_iter, __pred_iter, __iter_comp_val, __negate): Constexpr
ctors. Add const operator().
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
set_intersection, __set_difference, set_difference,
__set_symmetric_difference, set_symmetric_difference): Constexpr.
* include/bits/stl_algobase.h (__niter_base, __niter_wrap, __copy_m,
__copy_move_a, copy, move, __copy_move_backward::__copy_move_b,
__copy_move_backward_a, __copy_move_backward_a2, copy_backward,
move_backward, fill, __fill_a, __fill_n_a, fill_n, __equal::equal,
__equal_aux, __newlast1, __cnd2, __newlast1, __cnd2,
__lexicographical_compare_impl, __lexicographical_compare::__lc,
__lexicographical_compare, __lexicographical_compare_aux,
__lower_bound, lower_bound, equal, __equal4, lexicographical_compare,
__mismatch, mismatch): Constexpr.
(__memmove, __memcmp): New constexpr wrappers.
* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
is_heap): Constexpr.
* include/bits/stl_iterator.h (__niter_base, __miter_base): Constexpr.
* include/std/array: Make comparison ops constexpr.
* include/std/utility: Make exchange constexpr.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
* testsuite/23_containers/array/tuple_interface/
tuple_element_neg.cc: Adjust.
* testsuite/25_algorithms/copy_n/58982.cc: Adjust error scan.
* testsuite/25_algorithms/copy/58982.cc: Adjust error scan.
* testsuite/20_util/exchange/constexpr.cc: New.
* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
* testsuite/25_algorithms/headers/algorithm/synopsis.cc: Constexpr.
* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
* testsuite/25_algorithms/all_of/constexpr.cc: New.
* testsuite/25_algorithms/any_of/constexpr.cc: New.
* 

Re: Implement C++20 constexpr , , and

2019-03-19 Thread Ed Smith-Rowland via gcc-patches

On 3/19/19 4:57 PM, Ed Smith-Rowland via libstdc++ wrote:

On 3/18/19 6:18 PM, Jonathan Wakely wrote:

On 17/03/19 22:54 -0400, Ed Smith-Rowland via libstdc++ wrote:

Greetings,

This patch implements C++20 p0202 - Add Constexpr Modifiers to 
Functions in  and  Headers


and C++20 p1023 - constexpr comparison operators for std::array.


The patch is large because of the testsuite additions. Basically, 
the algorithms and the array comparison operators are all marked 
constexpr for C++20.  This has been built and tested on x86_64-linux.


As discussed on IRC< the tests need to be run with -std=gnu++2a to
ensure everything we test (which is not exhaustive, but is the best we
can do) still works in C++2a mode.

The indentation went bad here:

  template_BinaryPredicate>

-    _FIter1
+    _GLIBCXX20_CONSTEXPR
+   _FIter1
    find_first_of(_FIter1, _FIter1, _FIter2, _FIter2, _BinaryPredicate);

Fixed.


I would have to look through old emails but I think there's a reason
the function objects like _Iter_comp_to_val take their arguments by
non-const reference.

I'm very surprised that none of the algos that dispatch to
__builtin_memove need changes, because those optimizations won't work
in constant expressions. I would expect to have to use
std::is_constant_evaluated to disable the optimizations when used in
constant expressions.


As am I. As I mentioned on IRC I could roll a constexpr memmove.

I was wondering if somehow I'm not checking what I think I'm checking 
(but I don't see how.)


I wonder if the builtins are handled differently somehow by the front 
end.  I'm still not sure why __builtin_memcmp is OK for array == array 
but not array != array.  In that case I just do element by element 
compare for constexpr now anyway.


Ed


Ignore this patch,

I'm not actually getting constexpr.

Ed




Re: Implement C++20 constexpr , , and

2019-03-19 Thread Ed Smith-Rowland via gcc-patches

On 3/18/19 6:18 PM, Jonathan Wakely wrote:

On 17/03/19 22:54 -0400, Ed Smith-Rowland via libstdc++ wrote:

Greetings,

This patch implements C++20 p0202 - Add Constexpr Modifiers to 
Functions in  and  Headers


and C++20 p1023 - constexpr comparison operators for std::array.


The patch is large because of the testsuite additions. Basically, the 
algorithms and the array comparison operators are all marked 
constexpr for C++20.  This has been built and tested on x86_64-linux.


As discussed on IRC< the tests need to be run with -std=gnu++2a to
ensure everything we test (which is not exhaustive, but is the best we
can do) still works in C++2a mode.

The indentation went bad here:

  template
-    _FIter1
+    _GLIBCXX20_CONSTEXPR
+   _FIter1
    find_first_of(_FIter1, _FIter1, _FIter2, _FIter2, _BinaryPredicate);

Fixed.


I would have to look through old emails but I think there's a reason
the function objects like _Iter_comp_to_val take their arguments by
non-const reference.

I'm very surprised that none of the algos that dispatch to
__builtin_memove need changes, because those optimizations won't work
in constant expressions. I would expect to have to use
std::is_constant_evaluated to disable the optimizations when used in
constant expressions.


As am I. As I mentioned on IRC I could roll a constexpr memmove.

I was wondering if somehow I'm not checking what I think I'm checking 
(but I don't see how.)


I wonder if the builtins are handled differently somehow by the front 
end.  I'm still not sure why __builtin_memcmp is OK for array == array 
but not array != array.  In that case I just do element by element 
compare for constexpr now anyway.


Ed


2019-03-19  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, fill_n, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, lower_bound, none_of,
partition_copy, partition_point, remove, remove_if, remove_copy,
remove_copy_if, replace_copy, replace_copy_if, reverse_copy,
rotate_copy, unique, upper_bound, adjacent_find, count, count_if, equal,
find, find_first_of, find_if, for_each, generate, generate_n,
lexicographical_compare, merge, mismatch, replace, replace_if, search,
search_n, set_difference, set_intersection, set_symmetric_difference,
set_union, transform, unique_copy): Mark constexpr.
Make versions of operator() const.
* include/bits/cpp_type_traits.h (__miter_base): Make constexpr.
* include/bits/predefined_ops.h (_Iter_less_val, __iter_comp_val,
_Val_less_iter, __val_less_iter, __val_comp_iter, _Iter_equal_to_iter,
__iter_equal_to_iter, _Iter_equal_to_val, __iter_equal_to_val,
_Iter_comp_val, __iter_comp_val, _Val_comp_iter, __val_comp_iter,
_Iter_equals_val, __iter_equals_val, _Iter_equals_iter,
__iter_comp_iter, __pred_iter, __iter_comp_val, __negate): Constexpr
ctors. Add const operator().
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
set_intersection, __set_difference, set_difference,
__set_symmetric_difference, set_symmetric_difference): Constexpr.
* include/bits/stl_algobase.h (__niter_base, __niter_wrap, __copy_m,
__copy_move_a, copy, move, __copy_move_backward::__copy_move_b,
__copy_move_backward_a, __copy_move_backward_a2, copy_backward,
move_backward, fill, __fill_n_a, fill_n, __equal::equal, __equal_aux,
__newlast1, __cnd2, __newlast1, __cnd2, __lexicographical_compare_impl
__lexicographical_comp

Re: Implement C++20 constexpr , , and

2019-03-18 Thread Ed Smith-Rowland via gcc-patches

On 3/18/19 6:18 PM, Jonathan Wakely wrote:

On 17/03/19 22:54 -0400, Ed Smith-Rowland via libstdc++ wrote:

Greetings,

This patch implements C++20 p0202 - Add Constexpr Modifiers to 
Functions in  and  Headers


and C++20 p1023 - constexpr comparison operators for std::array.


The patch is large because of the testsuite additions. Basically, the 
algorithms and the array comparison operators are all marked 
constexpr for C++20.  This has been built and tested on x86_64-linux.


As discussed on IRC< the tests need to be run with -std=gnu++2a to
ensure everything we test (which is not exhaustive, but is the best we
can do) still works in C++2a mode.

The indentation went bad here:

  template
-    _FIter1
+    _GLIBCXX20_CONSTEXPR
+   _FIter1
    find_first_of(_FIter1, _FIter1, _FIter2, _FIter2, _BinaryPredicate);


I would have to look through old emails but I think there's a reason
the function objects like _Iter_comp_to_val take their arguments by
non-const reference.
The _Iter_comp_to_val functions need non-const reference o'loads to 
accommodate mutable functors.  These things now have both const and 
nonconst o'loads.


I'm very surprised that none of the algos that dispatch to
__builtin_memove need changes, because those optimizations won't work
in constant expressions. I would expect to have to use
std::is_constant_evaluated to disable the optimizations when used in
constant expressions


I'm also actually surprised that __builtin_memove works also.  In other 
strange news, I had to write a std::is_constant_evaluated branch around 
__builtin_memcmp even though *that* *is* supposed to work for constexpr.


Ed




Implement C++20 constexpr , , and

2019-03-17 Thread Ed Smith-Rowland via gcc-patches

Greetings,

This patch implements C++20 p0202 - Add Constexpr Modifiers to Functions 
in  and  Headers


and C++20 p1023 - constexpr comparison operators for std::array.


The patch is large because of the testsuite additions. Basically, the 
algorithms and the array comparison operators are all marked constexpr 
for C++20.  This has been built and tested on x86_64-linux.


OK?

Ed


2019-03-18  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++20 p0202 - Add Constexpr Modifiers to Functions
in  and  Headers.
Implement C++20 p1023 - constexpr comparison operators for std::array.
* include/bits/algorithmfwd.h (all_of, any_of, binary_search, copy,
copy_backward, copy_if, copy_n, equal_range, fill, fill_n, find_end,
find_if_not, includes, is_heap, is_heap_until, is_partitioned,
is_permutation, is_sorted, is_sorted_until, lower_bound, none_of,
partition_copy, partition_point, remove, remove_if, remove_copy,
remove_copy_if, replace_copy, replace_copy_if, reverse_copy,
rotate_copy, unique, upper_bound, adjacent_find, count, count_if, equal,
find, find_first_of, find_if, for_each, generate, generate_n,
lexicographical_compare, merge, mismatch, replace, replace_if, search,
search_n, set_difference, set_intersection, set_symmetric_difference,
set_union, transform, unique_copy): Mark constexpr.
Make versions of operator() const.
* include/bits/cpp_type_traits.h (__miter_base): Make constexpr.
* include/bits/predefined_ops.h (_Iter_less_val, __iter_comp_val,
_Val_less_iter, __val_less_iter, __val_comp_iter, _Iter_equal_to_iter,
__iter_equal_to_iter, _Iter_equal_to_val, __iter_equal_to_val,
_Iter_comp_val, __iter_comp_val, _Val_comp_iter, __val_comp_iter,
_Iter_equals_val, __iter_equals_val, _Iter_equals_iter,
__iter_comp_iter, __pred_iter, __iter_comp_val, __negate): Constexpr
ctors. Add const operator().
* include/bits/stl_algo.h (__find_if, __find_if_not, __find_if_not_n,
__search, __search_n_aux, __search_n, __find_end, find_end, all_of
none_of, any_of, find_if_not, is_partitioned, partition_point,
__remove_copy_if, remove_copy, remove_copy_if, copy_if, __copy_n,
copy_n, partition_copy, __remove_if, remove, remove_if, __adjacent_find,
__unique, unique, __unique_copy, reverse_copy, rotate_copy,
__unguarded_linear_insert, __insertion_sort, __unguarded_insertion_sort,
__final_insertion_sort, lower_bound, __upper_bound, upper_bound,
__equal_range, equal_range, binary_search, __includes, includes,
__next_permutation, __prev_permutation, __replace_copy_if, replace_copy,
replace_copy_if, __count_if, is_sorted, __is_sorted_until,
is_sorted_until, __is_permutation, is_permutation, for_each, find,
find_if, find_first_of, adjacent_find, count, count_if, search,
search_n, transform, replace, replace_if, generate, generate_n,
unique_copy, __merge, merge, __set_union, set_union, __set_intersection,
set_intersection, __set_difference, set_difference,
__set_symmetric_difference, set_symmetric_difference): Constexpr.
* include/bits/stl_algobase.h (__niter_base, __niter_wrap, __copy_m,
__copy_move_a, copy, move, __copy_move_backward::__copy_move_b,
__copy_move_backward_a, __copy_move_backward_a2, copy_backward,
move_backward, fill, __fill_n_a, fill_n, __equal::equal, __equal_aux,
__newlast1, __cnd2, __newlast1, __cnd2, __lexicographical_compare_impl
__lexicographical_compare::__lc, __lexicographical_compare,
__lexicographical_compare_aux, __lower_bound, lower_bound, equal,
__equal4, lexicographical_compare, __mismatch, mismatch): Constexpr.
* include/bits/stl_heap.h (__is_heap_until, __is_heap, is_heap_until,
is_heap): Constexpr.
* include/bits/stl_iterator.h (__niter_base, __miter_base): Constexpr.
* include/std/array: Make comparison ops constexpr.
* include/std/utility: Make exchange constexpr.
* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
* testsuite/23_containers/array/tuple_interface/
tuple_element_neg.cc: Adjust.
* testsuite/20_util/exchange/constexpr.cc: New.
* testsuite/23_containers/array/comparison_operators/constexpr.cc: New.
* testsuite/25_algorithms/adjacent_find/constexpr.cc: New.
* testsuite/25_algorithms/all_of/constexpr.cc: New.
* testsuite/25_algorithms/any_of/constexpr.cc: New.
* testsuite/25_algorithms/binary_search/constexpr.cc: New.
* testsuite/25_algorithms/copy/constexpr.cc: New.
* testsuite/25_algorithms/copy_backward/constexpr.cc: New.
* testsuite/25_algorithms/copy_if/constexpr.cc: New.
* testsuite/25_algorithms/copy_n/constexpr.cc: New.
* 

Re: [PATCH] PR libstdc++/88996 Implement P0439R0 - C++20 - Make std::memory_order a scoped enumeration.

2019-03-04 Thread Ed Smith-Rowland

On 3/4/19 3:05 PM, Jonathan Wakely wrote:

On 04/02/19 14:26 +, Jonathan Wakely wrote:

On 24/01/19 14:50 -0500, Ed Smith-Rowland wrote:

PR libstdc++/88996 Implement P0439R0
Make std::memory_order a scoped enumeration.
* include/bits/atomic_base.h: For C++20 make memory_order a 
scoped enum,

add assignments for the old constants.  Adjust calls.


I think it would be more accurate to say "variables for the old
enumerators" rather than "assignments for the old constants".

As this only affects C++2a it's OK for trunk now, thanks.

Somehow I missed this.

Hi Ed, it looks like this wasn't committed yet. Could you please go
ahead and commit it to trunk (ideally with the changelog tweak I
suggested above).

Thanks!


Done.

Thank you.

Ed


I




Re: [libstc++] Don't throw in std::assoc_legendre for m > l

2019-03-04 Thread Ed Smith-Rowland

This is actually PR libstdc++/86655.

Thank you for reminding me Andre.

I remove the throw for m > l and just return 0.  This is also done for 
sph_legendre.


This build and tests clean on x86_64-linux.

OK?

Ed


2018-03-04  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/86655 - std::assoc_legendre should not constrain
the value of m (or x).
* include/tr1/legendre_function.tcc (__assoc_legendre_p,
__sph_legendre): If degree > order Don't throw, return 0.
(__legendre_p, __assoc_legendre_p): Don't constrain x either.
* testsuite/special_functions/02_assoc_legendre/pr86655.cc: New test.
* testsuite/special_functions/20_sph_legendre/pr86655.cc: New test.
* testsuite/tr1/5_numerical_facilities/special_functions/
02_assoc_legendre/pr86655.cc: New test.
* testsuite/tr1/5_numerical_facilities/special_functions/
22_sph_legendre/pr86655.cc: New test.

Index: include/tr1/legendre_function.tcc
===
--- include/tr1/legendre_function.tcc   (revision 269347)
+++ include/tr1/legendre_function.tcc   (working copy)
@@ -82,10 +82,7 @@
 __poly_legendre_p(unsigned int __l, _Tp __x)
 {
 
-  if ((__x < _Tp(-1)) || (__x > _Tp(+1)))
-std::__throw_domain_error(__N("Argument out of range"
-  " in __poly_legendre_p."));
-  else if (__isnan(__x))
+  if (__isnan(__x))
 return std::numeric_limits<_Tp>::quiet_NaN();
   else if (__x == +_Tp(1))
 return +_Tp(1);
@@ -126,11 +123,11 @@
  *   @f[
  * P_l^m(x) = (1 - x^2)^{m/2}\frac{d^m}{dx^m}P_l(x)
  *   @f]
+ *   @note @f$ P_l^m(x) = 0 @f$ if @f$ m > l @f$.
  * 
  *   @param  l  The degree of the associated Legendre function.
  *  @f$ l >= 0 @f$.
  *   @param  m  The order of the associated Legendre function.
- *  @f$ m <= l @f$.
  *   @param  x  The argument of the associated Legendre function.
  *  @f$ |x| <= 1 @f$.
  *   @param  phase  The phase of the associated Legendre function.
@@ -142,12 +139,8 @@
   _Tp __phase = _Tp(+1))
 {
 
-  if (__x < _Tp(-1) || __x > _Tp(+1))
-std::__throw_domain_error(__N("Argument out of range"
-  " in __assoc_legendre_p."));
-  else if (__m > __l)
-std::__throw_domain_error(__N("Degree out of range"
-  " in __assoc_legendre_p."));
+  if (__m > __l)
+return _Tp(0);
   else if (__isnan(__x))
 return std::numeric_limits<_Tp>::quiet_NaN();
   else if (__m == 0)
@@ -209,12 +202,12 @@
  *   and so this function is stable for larger differences of @f$ l @f$
  *   and @f$ m @f$.
  *   @note Unlike the case for __assoc_legendre_p the Condon-Shortley
- *   phase factor @f$ (-1)^m @f$ is present here.
+ * phase factor @f$ (-1)^m @f$ is present here.
+ *   @note @f$ Y_l^m(\theta) = 0 @f$ if @f$ m > l @f$.
  * 
  *   @param  l  The degree of the spherical associated Legendre function.
  *  @f$ l >= 0 @f$.
  *   @param  m  The order of the spherical associated Legendre function.
- *  @f$ m <= l @f$.
  *   @param  theta  The radian angle argument of the spherical associated
  *  Legendre function.
  */
@@ -227,11 +220,8 @@
 
   const _Tp __x = std::cos(__theta);
 
-  if (__l < __m)
-{
-  std::__throw_domain_error(__N("Bad argument "
-"in __sph_legendre."));
-}
+  if (__m > __l)
+return _Tp(0);
   else if (__m == 0)
 {
   _Tp __P = __poly_legendre_p(__l, __x);
@@ -284,7 +274,7 @@
   _Tp __y_lm = _Tp(0);
 
   // Compute Y_l^m, l > m+1, upward recursion on l.
-  for (unsigned int __ll = __m + 2; __ll <= __l; ++__ll)
+  for (int __ll = __m + 2; __ll <= __l; ++__ll)
 {
   const _Tp __rat1 = _Tp(__ll - __m) / _Tp(__ll + __m);
   const _Tp __rat2 = _Tp(__ll - __m - 1) / _Tp(__ll + __m - 1);
Index: testsuite/special_functions/02_assoc_legendre/pr86655.cc
===
--- testsuite/special_functions/02_assoc_legendre/pr86655.cc(nonexistent)
+++ testsuite/special_functions/02_assoc_legendre/pr86655.cc(working copy)
@@ -0,0 +1,56 @@
+// { dg-do run { target c++11 } }
+// { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__ -ffp-contract=off" }
+
+// Copyright (C) 2019 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 

[PATCH] PR libstdc++/88996 Implement P0439R0 - C++20 - Make std::memory_order a scoped enumeration.

2019-01-24 Thread Ed Smith-Rowland

Greetings,

This makes memory_order in  a scoped enum *only* for C++20.

This is built and tested on x86_64-linux.

OK?


Index: include/bits/atomic_base.h
===
--- include/bits/atomic_base.h  (revision 268246)
+++ include/bits/atomic_base.h  (working copy)
@@ -52,6 +52,24 @@
*/
 
   /// Enumeration for memory_order
+#if __cplusplus > 201703L
+  enum class memory_order : int
+{
+  relaxed,
+  consume,
+  acquire,
+  release,
+  acq_rel,
+  seq_cst
+};
+
+  inline constexpr memory_order memory_order_relaxed = memory_order::relaxed;
+  inline constexpr memory_order memory_order_consume = memory_order::consume;
+  inline constexpr memory_order memory_order_acquire = memory_order::acquire;
+  inline constexpr memory_order memory_order_release = memory_order::release;
+  inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel;
+  inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst;
+#else
   typedef enum memory_order
 {
   memory_order_relaxed,
@@ -61,6 +79,7 @@
   memory_order_acq_rel,
   memory_order_seq_cst
 } memory_order;
+#endif
 
   enum __memory_order_modifier
 {
@@ -73,13 +92,13 @@
   constexpr memory_order
   operator|(memory_order __m, __memory_order_modifier __mod)
   {
-return memory_order(__m | int(__mod));
+return memory_order(int(__m) | int(__mod));
   }
 
   constexpr memory_order
   operator&(memory_order __m, __memory_order_modifier __mod)
   {
-return memory_order(__m & int(__mod));
+return memory_order(int(__m) & int(__mod));
   }
 
   // Drop release ordering as per [atomics.types.operations.req]/21
@@ -94,16 +113,16 @@
   __cmpexch_failure_order(memory_order __m) noexcept
   {
 return memory_order(__cmpexch_failure_order2(__m & __memory_order_mask)
-  | (__m & __memory_order_modifier_mask));
+  | __memory_order_modifier(__m & __memory_order_modifier_mask));
   }
 
   _GLIBCXX_ALWAYS_INLINE void
   atomic_thread_fence(memory_order __m) noexcept
-  { __atomic_thread_fence(__m); }
+  { __atomic_thread_fence(int(__m)); }
 
   _GLIBCXX_ALWAYS_INLINE void
   atomic_signal_fence(memory_order __m) noexcept
-  { __atomic_signal_fence(__m); }
+  { __atomic_signal_fence(int(__m)); }
 
   /// kill_dependency
   template
@@ -173,13 +192,13 @@
 _GLIBCXX_ALWAYS_INLINE bool
 test_and_set(memory_order __m = memory_order_seq_cst) noexcept
 {
-  return __atomic_test_and_set (&_M_i, __m);
+  return __atomic_test_and_set (&_M_i, int(__m));
 }
 
 _GLIBCXX_ALWAYS_INLINE bool
 test_and_set(memory_order __m = memory_order_seq_cst) volatile noexcept
 {
-  return __atomic_test_and_set (&_M_i, __m);
+  return __atomic_test_and_set (&_M_i, int(__m));
 }
 
 _GLIBCXX_ALWAYS_INLINE void
@@ -190,7 +209,7 @@
   __glibcxx_assert(__b != memory_order_acquire);
   __glibcxx_assert(__b != memory_order_acq_rel);
 
-  __atomic_clear (&_M_i, __m);
+  __atomic_clear (&_M_i, int(__m));
 }
 
 _GLIBCXX_ALWAYS_INLINE void
@@ -201,7 +220,7 @@
   __glibcxx_assert(__b != memory_order_acquire);
   __glibcxx_assert(__b != memory_order_acq_rel);
 
-  __atomic_clear (&_M_i, __m);
+  __atomic_clear (&_M_i, int(__m));
 }
 
   private:
@@ -374,7 +393,7 @@
__glibcxx_assert(__b != memory_order_acq_rel);
__glibcxx_assert(__b != memory_order_consume);
 
-   __atomic_store_n(&_M_i, __i, __m);
+   __atomic_store_n(&_M_i, __i, int(__m));
   }
 
   _GLIBCXX_ALWAYS_INLINE void
@@ -386,7 +405,7 @@
__glibcxx_assert(__b != memory_order_acq_rel);
__glibcxx_assert(__b != memory_order_consume);
 
-   __atomic_store_n(&_M_i, __i, __m);
+   __atomic_store_n(&_M_i, __i, int(__m));
   }
 
   _GLIBCXX_ALWAYS_INLINE __int_type
@@ -396,7 +415,7 @@
__glibcxx_assert(__b != memory_order_release);
__glibcxx_assert(__b != memory_order_acq_rel);
 
-   return __atomic_load_n(&_M_i, __m);
+   return __atomic_load_n(&_M_i, int(__m));
   }
 
   _GLIBCXX_ALWAYS_INLINE __int_type
@@ -406,7 +425,7 @@
__glibcxx_assert(__b != memory_order_release);
__glibcxx_assert(__b != memory_order_acq_rel);
 
-   return __atomic_load_n(&_M_i, __m);
+   return __atomic_load_n(&_M_i, int(__m));
   }
 
   _GLIBCXX_ALWAYS_INLINE __int_type
@@ -413,7 +432,7 @@
   exchange(__int_type __i,
   memory_order __m = memory_order_seq_cst) noexcept
   {
-   return __atomic_exchange_n(&_M_i, __i, __m);
+   return __atomic_exchange_n(&_M_i, __i, int(__m));
   }
 
 
@@ -421,7 +440,7 @@
   exchange(__int_type __i,
   memory_order __m = memory_order_seq_cst) volatile noexcept
   {
-   return __atomic_exchange_n(&_M_i, __i, __m);
+   return __atomic_exchange_n(&_M_i, __i, int(__m));
   }
 
   _GLIBCXX_ALWAYS_INLINE bool
@@ -434,7 

Re: [RFA] fix copyright year range in libstdc++ test file

2019-01-01 Thread Ed Smith-Rowland

On 1/1/19 12:45 AM, Joel Brobecker wrote:

Hello,

In working on updating the copyright year notices for the GDB files,
I noticed something very minor regarding the patch which added the
file below (the same file was copied in gdb's testsuite); it looks
like the year range for one of the files is truncated:

 | diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/empty.cc
 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/empty.cc
 | new file mode 100644
 | index 000..c0f8206
 | --- /dev/null
 | +++ 
b/libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/empty.cc
 | @@ -0,0 +1,40 @@
 | +// { dg-options "-std=gnu++17" }
 | +
 | +// Copyright (C) 3 Free Software Foundation, Inc.

The file was contributed around July 2016, so it should be at least
2016-2018 now, but, looking at all the other test files around,
all ranges start with 2013, so I suspect the intention was for
this file to be the same. This is what the attached patch proposes.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string_view/element_access/char/empty.cc:
 Fix year range in copyright header.

OK for trunk?

One a fix pushed to GCC, I will take care of the GDB side.

Thank you,


Seems obvious to me.

Ed




[PATCH PR libstdc++/88341] -

2018-12-04 Thread Ed Smith-Rowland

Committed as obvious 266788.

Ed


2018-12-03  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/88341 - Complex norm doesn't compile with C++11
* include/std/complex (_S_do_it): Make C++20 constexpr.
* testsuite/26_numerics/complex/value_operations/pr88341.cc: New test.

Index: include/std/complex
===
--- include/std/complex (revision 266769)
+++ include/std/complex (working copy)
@@ -659,7 +659,7 @@
 struct _Norm_helper
 {
   template
-static inline _GLIBCXX_CONSTEXPR _Tp _S_do_it(const complex<_Tp>& __z)
+static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(const complex<_Tp>& 
__z)
 {
   const _Tp __x = __z.real();
   const _Tp __y = __z.imag();
@@ -671,7 +671,7 @@
 struct _Norm_helper
 {
   template
-static inline _GLIBCXX_CONSTEXPR _Tp _S_do_it(const complex<_Tp>& __z)
+static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(const complex<_Tp>& 
__z)
 {
   //_Tp __res = std::abs(__z);
   //return __res * __res;
Index: testsuite/26_numerics/complex/value_operations/pr88341.cc
===
--- testsuite/26_numerics/complex/value_operations/pr88341.cc   (nonexistent)
+++ testsuite/26_numerics/complex/value_operations/pr88341.cc   (working copy)
@@ -0,0 +1,27 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do compile { target c++11 } }
+
+// Copyright (C) 2018 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
+// .
+
+#include 
+
+double
+n(std::complex& c)
+{
+  return std::norm(c);
+}


Re: [PATCH, libstdc++, C++20] Implement P0457R2 String Prefix and Suffix Checking.

2018-11-30 Thread Ed Smith-Rowland

On 11/30/18 5:33 AM, Jonathan Wakely wrote:

On 29/11/18 21:35 -0500, Ed Smith-Rowland wrote:

Greetings,

This patch implements starts_with and ends_with for basic_string and 
basic_string_view for C++20.


This was on my TODO list, thanks for taking care of it.


+#if __cplusplus > 201703L
+  bool
+  starts_with(basic_string_view<_CharT, _Traits> __x) const 
noexcept
+  { return __sv_type(this->data(), 
this->size()).starts_with(__x); }

+
+  bool
+  starts_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), 
this->size()).starts_with(__x); }

+
+  bool
+  starts_with(const _CharT* __x) const


This can be noexcept. It isn't in the standard, because it has a
narrow contract (there's a precondition that __x is null-terminated).
But since we can't reliably detect whether __x is null-terminated, and
even if we could we wouldn't want to throw an exception, we can just
make it noexcept. Same for the ends_with(const _CharT*) one, and the
equivalent members in the COW basic_string and basic_string_view.


Index: include/std/string_view
===
--- include/std/string_view    (revision 266645)
+++ include/std/string_view    (working copy)
@@ -227,7 +227,6 @@
__sv = __tmp;
  }

-
  // [string.view.ops], string operations:

  size_type
@@ -387,6 +386,36 @@
  traits_type::length(__str));
  }

+#if __cplusplus > 201703L
+  constexpr bool
+  starts_with(basic_string_view __x) const noexcept
+  { return this->size() >= __x.size()
+    && this->compare(0, __x.size(), __x) == 0; }


Please put the opening and closing braces on their own lines, as for
ends_with below:


+  constexpr bool
+  ends_with(basic_string_view __x) const noexcept
+  {
+    return this->size() >= __x.size()
+    && this->compare(this->size() - __x.size(), npos, __x) == 0;
+  }


OK with those changes, thanks


Committed 266674.

New patch attached.

Ed



2018-11-30  Edward Smith-Rowland  <3dw...@verizon.net>

Implement P0457R2 String Prefix and Suffix Checking.
* include/bits/basic_string.h: Add starts_with, ends_with members.
* include/std/string_view: Ditto.
* testsuite/21_strings/basic_string/operations/starts_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string/operations/starts_with/
wchar_t/1.cc: New test.
* testsuite/21_strings/basic_string/operations/ends_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string/operations/ends_with/
wchar_t/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/starts_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/starts_with/
wchar_t/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/ends_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/ends_with/
wchar_t/1.cc: New test.

Index: include/bits/basic_string.h
===
--- include/bits/basic_string.h (revision 266671)
+++ include/bits/basic_string.h (working copy)
@@ -3038,6 +3038,32 @@
   compare(size_type __pos, size_type __n1, const _CharT* __s,
  size_type __n2) const;
 
+#if __cplusplus > 201703L
+  bool
+  starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  starts_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  starts_with(const _CharT* __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+
+  bool
+  ends_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+
+  bool
+  ends_with(const _CharT* __x) const noexcept
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+#endif // C++20
+
   // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
   template friend class basic_stringbuf;
 };
@@ -5884,6 +5910,32 @@
   compare(size_type __pos, size_type __n1, const _CharT* __s,
  size_type __n2) const;
 
+#if __cplusplus > 201703L
+  bool
+  starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  starts_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()

[PATCH, libstdc++, C++20] Implement P0457R2 String Prefix and Suffix Checking.

2018-11-29 Thread Ed Smith-Rowland

Greetings,

This patch implements starts_with and ends_with for basic_string and 
basic_string_view for C++20.


This builds and tests cleanly on x86_64-linux.

Ed



2018-11-30  Edward Smith-Rowland  <3dw...@verizon.net>

Implement P0457R2 String Prefix and Suffix Checking.
* include/bits/basic_string.h: Add starts_with, ends_with members.
* include/std/string_view: Ditto.
* testsuite/21_strings/basic_string/operations/starts_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string/operations/starts_with/
wchar_t/1.cc: New test.
* testsuite/21_strings/basic_string/operations/ends_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string/operations/ends_with/
wchar_t/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/starts_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/starts_with/
wchar_t/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/ends_with/
char/1.cc: New test.
* testsuite/21_strings/basic_string_view/operations/ends_with/
wchar_t/1.cc: New test.

Index: include/bits/basic_string.h
===
--- include/bits/basic_string.h (revision 266645)
+++ include/bits/basic_string.h (working copy)
@@ -3038,6 +3038,32 @@
   compare(size_type __pos, size_type __n1, const _CharT* __s,
  size_type __n2) const;
 
+#if __cplusplus > 201703L
+  bool
+  starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  starts_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  starts_with(const _CharT* __x) const
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+
+  bool
+  ends_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+
+  bool
+  ends_with(const _CharT* __x) const
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+#endif // C++20
+
   // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
   template friend class basic_stringbuf;
 };
@@ -5884,6 +5910,32 @@
   compare(size_type __pos, size_type __n1, const _CharT* __s,
  size_type __n2) const;
 
+#if __cplusplus > 201703L
+  bool
+  starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  starts_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  starts_with(const _CharT* __x) const
+  { return __sv_type(this->data(), this->size()).starts_with(__x); }
+
+  bool
+  ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+
+  bool
+  ends_with(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+
+  bool
+  ends_with(const _CharT* __x) const
+  { return __sv_type(this->data(), this->size()).ends_with(__x); }
+#endif // C++20
+
 # ifdef _GLIBCXX_TM_TS_INTERNAL
   friend void
   ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s,
Index: include/std/string_view
===
--- include/std/string_view (revision 266645)
+++ include/std/string_view (working copy)
@@ -227,7 +227,6 @@
__sv = __tmp;
   }
 
-
   // [string.view.ops], string operations:
 
   size_type
@@ -387,6 +386,36 @@
  traits_type::length(__str));
   }
 
+#if __cplusplus > 201703L
+  constexpr bool
+  starts_with(basic_string_view __x) const noexcept
+  { return this->size() >= __x.size()
+   && this->compare(0, __x.size(), __x) == 0; }
+
+  constexpr bool
+  starts_with(_CharT __x) const noexcept
+  { return this->starts_with(basic_string_view(&__x, 1)); }
+
+  constexpr bool
+  starts_with(const _CharT* __x) const
+  { return this->starts_with(basic_string_view(__x)); }
+
+  constexpr bool
+  ends_with(basic_string_view __x) const noexcept
+  {
+   return this->size() >= __x.size()
+   && this->compare(this->size() - __x.size(), npos, __x) == 0;
+  }
+
+  constexpr bool
+  ends_with(_CharT __x) const noexcept
+  { return this->ends_with(basic_string_view(&__x, 1)); }
+
+  constexpr bool
+  ends_with(const _CharT* __x) const
+  { return 

[PATCH, libstdc++] Uniform container erasure for c++20 returning number of erasures.

2018-11-29 Thread Ed Smith-Rowland
This version of erase_if/erase returning number erased actually build 
and tests cleanly on x86_64-linux.


Is this what you has in mind for this?  I basically return the number of 
erased items for all the things


Ed




Re: [PATCH, libstdc++] Uniform container erasure for c++20.

2018-11-29 Thread Ed Smith-Rowland

On 11/26/18 6:18 AM, Jonathan Wakely wrote:

On 24/11/18 13:54 -0500, Ed Smith-Rowland wrote:

All,

I's very late but uniform container erasure is, I think, the last 
little tidbit to graduate from fundamentals/v2 to std at the last 
meeting.  I think it would be a shame not to nudge this into gcc-9.  
The routines are very short so I just copied them. Ditto the 
testcases (with adjustments).  The node erasure tool was moved from 
experimental to std/bits and adjustments made to affected *set/*map 
headers.


The experimental code has been in our tree since 2015.

This builds and tests clean on x86_64-linux.


OK for trunk as it only touches experimental C++2a and TS material.
Thanks.

I pointed out to the committee that the erase_if functions added to
C++20 completely overlook P0646R1 "Improving the Return Value of
Erase-Like Algorithms" and so fail to preserve the useful information
returned by the members of the linked list containers.
Is *this* what you has in mind for this?  I basically return the number 
of erased items for all the things.


I expect that to get fixed as a defect. If you have time and
motivation, I think we should make that change proactively in
libstdc++. The Library Fundamentals versions can continue to return
void, but the ones in namespace std can return the number of elements
removed


Ed



2018-11-29  Edward Smith-Rowland  <3dw...@verizon.net>

Pre-emptively support P0646R1 for std container erasure.
* include/bits/erase_if.h: Accumulate and return number of erased nodes.
* include/std/forward_list (): Return number of erased items.
* include/std/list (): Ditto.
* include/std/map (): Ditto.
* include/std/set (): Ditto.
* include/std/string (): Ditto.
* include/std/unordered_map (): Ditto.
* include/std/unordered_set (): Ditto.
* include/std/vector (): Ditto.
* testsuite/21_strings/basic_string/erasure.cc: Test number of erasures.
* testsuite/23_containers/deque/erasure.cc: Ditto.
* testsuite/23_containers/forward_list/erasure.cc: Ditto.
* testsuite/23_containers/list/erasure.cc: Ditto.
* testsuite/23_containers/map/erasure.cc: Ditto.
* testsuite/23_containers/set/erasure.cc: Ditto.
* testsuite/23_containers/unordered_map/erasure.cc: Ditto.
* testsuite/23_containers/unordered_set/erasure.cc: Ditto.
* testsuite/23_containers/vector/erasure.cc: Ditto.

Index: include/bits/erase_if.h
===
--- include/bits/erase_if.h (revision 266623)
+++ include/bits/erase_if.h (working copy)
@@ -41,17 +41,22 @@
   namespace __detail
   {
 template
-  void
+  typename _Container::size_type
   __erase_nodes_if(_Container& __cont, _Predicate __pred)
   {
+   typename _Container::size_type __num = 0;
for (auto __iter = __cont.begin(), __last = __cont.end();
 __iter != __last;)
-   {
- if (__pred(*__iter))
-   __iter = __cont.erase(__iter);
- else
-   ++__iter;
-   }
+ {
+   if (__pred(*__iter))
+ {
+   __iter = __cont.erase(__iter);
+   ++__num;
+ }
+   else
+ ++__iter;
+ }
+   return __num;
   }
   } // namespace __detail
 
Index: include/std/forward_list
===
--- include/std/forward_list(revision 266623)
+++ include/std/forward_list(working copy)
@@ -66,16 +66,17 @@
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
-inline void 
+inline typename forward_list<_Tp, _Alloc>::size_type 
 erase_if(forward_list<_Tp, _Alloc>& __cont, _Predicate __pred)
-{ __cont.remove_if(__pred); }
+{ return __cont.remove_if(__pred); }
 
   template
-inline void
+inline typename forward_list<_Tp, _Alloc>::size_type
 erase(forward_list<_Tp, _Alloc>& __cont, const _Up& __value)
 {
   using __elem_type = typename forward_list<_Tp, _Alloc>::value_type;
-  erase_if(__cont, [&](__elem_type& __elem) { return __elem == __value; });
+  return erase_if(__cont,
+ [&](__elem_type& __elem) { return __elem == __value; });
 }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
Index: include/std/list
===
--- include/std/list(revision 266623)
+++ include/std/list(working copy)
@@ -90,16 +90,17 @@
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template
-inline void
+inline typename list<_Tp, _Alloc>::size_type
 erase_if(list<_Tp, _Alloc>& __cont, _Predicate __pred)
-{ __cont.remove_if(__pred); }
+{ return __cont.remove_if(__pred); }
 
   template
-inline void
+inline typename list<_Tp, _Alloc>::size_type

Re: [PATCH, libstdc++] Uniform container erasure for c++20.

2018-11-29 Thread Ed Smith-Rowland

On 11/29/18 9:09 AM, Jonathan Wakely wrote:

On 29/11/18 08:47 -0500, Ed Smith-Rowland wrote:

Fixed with 266616.


Thanks!


Index: include/std/deque
===
--- include/std/deque    (revision 266567)
+++ include/std/deque    (working copy)
@@ -58,6 +58,7 @@
#pragma GCC system_header

#include 
+#include  // For remove and remove_if


Please only include  when __cplusplus > 201703L
otherwise we include hundreds of kilobytes of code just for these tiny
functions that aren't even defined in the default C++14 dialect.


Done with 266624.

Ed


At some point I'll split std::remove and std::remove_if into their own
header, and we can just include that instead




2018-11-29  Edward Smith-Rowland  <3dw...@verizon.net>

Only include bits/stl_algo.h for C++20.
* include/std/deque: Only include bits/stl_algo.h for C++20.
* include/std/string: Ditto.
* include/std/vector: Ditto.

Index: include/std/deque
===
--- include/std/deque   (revision 266616)
+++ include/std/deque   (working copy)
@@ -58,7 +58,9 @@
 #pragma GCC system_header
 
 #include 
-#include  // For remove and remove_if
+#if __cplusplus > 201703L
+#  include  // For remove and remove_if
+#endif // C++20
 #include 
 #include 
 #include 
Index: include/std/string
===
--- include/std/string  (revision 266616)
+++ include/std/string  (working copy)
@@ -48,7 +48,9 @@
 #include  // For less
 #include 
 #include 
-#include  // For remove and remove_if
+#if __cplusplus > 201703L
+#  include  // For remove and remove_if
+#endif // C++20
 #include 
 #include 
 #include 
Index: include/std/vector
===
--- include/std/vector  (revision 266616)
+++ include/std/vector  (working copy)
@@ -58,7 +58,9 @@
 #pragma GCC system_header
 
 #include 
-#include  // For remove and remove_if
+#if __cplusplus > 201703L
+#  include  // For remove and remove_if
+#endif // C++20
 #include 
 #include 
 #include 


Re: [PATCH, libstdc++] Uniform container erasure for c++20.

2018-11-29 Thread Ed Smith-Rowland

On 11/28/18 7:25 PM, Jonathan Wakely wrote:

On 28/11/18 12:12 -0500, Ed Smith-Rowland wrote:

Index: testsuite/21_strings/basic_string/erasure.cc
===
--- testsuite/21_strings/basic_string/erasure.cc (nonexistent)
+++ testsuite/21_strings/basic_string/erasure.cc    (working copy)
@@ -0,0 +1,53 @@
+// { dg-do run { target c++2a } }
+


None of these new tests actually run by default, because they are
gated to only run for C++2a and the default is gnu++14. That means
they're all skipped as UNSUPPORTED.

(When I add new tests I always try to remember to check the
testsuite/libstdc++.sum file to make sure they are actually running).

The tests need an explicit -std option added via dg-options, which has
to come before the dg-do directive, otherwise the target check still
uses the default options i.e.

// { dg-options "-std=gnu++2a" }
// { dg-do run { target c++2a } }

With that added, most of them start to FAIL:

FAIL: 23_containers/deque/erasure.cc (test for excess errors)
UNRESOLVED: 23_containers/deque/erasure.cc compilation failed to 
produce executable

FAIL: 23_containers/unordered_set/erasure.cc (test for excess errors)
UNRESOLVED: 23_containers/unordered_set/erasure.cc compilation failed 
to produce executable

FAIL: 23_containers/vector/erasure.cc (test for excess errors)
UNRESOLVED: 23_containers/vector/erasure.cc compilation failed to 
produce executable

FAIL: experimental/deque/erasure.cc (test for excess errors)
UNRESOLVED: experimental/deque/erasure.cc compilation failed to 
produce executable

FAIL: experimental/forward_list/erasure.cc (test for excess errors)
UNRESOLVED: experimental/forward_list/erasure.cc compilation failed to 
produce executable

FAIL: experimental/list/erasure.cc (test for excess errors)
UNRESOLVED: experimental/list/erasure.cc compilation failed to produce 
executable

FAIL: experimental/vector/erasure.cc (test for excess errors)
UNRESOLVED: experimental/vector/erasure.cc compilation failed to 
produce executable



The errors are all like:

In file included from 
/home/jwakely/src/gcc/gcc/libstdc++-v3/testsuite/23_containers/vector/erasure.cc:21:
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/vector: 
In function 'void std::erase_if(std::vector<_Tp, _Alloc>&, _Predicate)':
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/vector:101: 
error: 'remove_if' is not a member of 'std'; did you mean 'remove_cv'?
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/vector: 
In function 'void std::erase(std::vector<_Tp, _Alloc>&, const _Up&)':
/home/jwakely/src/gcc/build/x86_64-pc-linux-gnu/libstdc++-v3/include/vector:109: 
error: 'remove' is not a member of 'std'; did you mean 'move'?


This is because std::remove and std::remove_if are defined in
 which is not included.

Could you please fix this ASAP 



Sorry about that.

Fixed with 266616.

Ed



2018-11-29  Edward Smith-Rowland  <3dw...@verizon.net>

Fix erasure goofs.
* include/experimental/deque: Make inline.
* include/std/deque: Include bits/stl_algo.h.
(erase, erase_if): Make inline.
* include/std/string: Include bits/stl_algo.h.
* include/std/unordered_set: Add erase, erase_if!
* include/std/vector: Include bits/stl_algo.h.
* testsuite/21_strings/basic_string/erasure.cc:
Add { dg-options "-std=gnu++2a" }.
* testsuite/23_containers/deque/erasure.cc: Ditto.
* testsuite/23_containers/forward_list/erasure.cc: Ditto.
* testsuite/23_containers/list/erasure.cc: Ditto.
* testsuite/23_containers/map/erasure.cc: Ditto.
* testsuite/23_containers/set/erasure.cc: Ditto.
* testsuite/23_containers/unordered_map/erasure.cc: Ditto.
* testsuite/23_containers/unordered_set/erasure.cc: Ditto.
* testsuite/23_containers/vector/erasure.cc: Ditto.

Index: include/experimental/deque
===
--- include/experimental/deque  (revision 266566)
+++ include/experimental/deque  (working copy)
@@ -46,7 +46,7 @@
 inline namespace fundamentals_v2
 {
   template
-void
+inline void
 erase_if(deque<_Tp, _Alloc>& __cont, _Predicate __pred)
 {
   __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred),
@@ -54,7 +54,7 @@
 }
 
   template
-void
+inline void
 erase(deque<_Tp, _Alloc>& __cont, const _Up& __value)
 {
   __cont.erase(std::remove(__cont.begin(), __cont.end(), __value),
Index: include/std/deque
===
--- include/std/deque   (revision 266567)
+++ include/std/deque   (working copy)
@@ -58,6 +58,7 @@
 #pragma GCC system_header
 
 #include 
+#include  // For remove and remove_if
 #include 
 #include 
 #include 
@@ -92,7 +93,7 @@
 {
 _GLIBCXX_BEGIN_NAMESP

Re: [PATCH, libstdc++] Uniform container erasure for c++20.

2018-11-28 Thread Ed Smith-Rowland

On 11/26/18 6:18 AM, Jonathan Wakely wrote:

On 24/11/18 13:54 -0500, Ed Smith-Rowland wrote:

All,

I's very late but uniform container erasure is, I think, the last 
little tidbit to graduate from fundamentals/v2 to std at the last 
meeting.  I think it would be a shame not to nudge this into gcc-9.  
The routines are very short so I just copied them. Ditto the 
testcases (with adjustments).  The node erasure tool was moved from 
experimental to std/bits and adjustments made to affected *set/*map 
headers.


The experimental code has been in our tree since 2015.

This builds and tests clean on x86_64-linux.


OK for trunk as it only touches experimental C++2a and TS material.
Thanks.

I pointed out to the committee that the erase_if functions added to
C++20 completely overlook P0646R1 "Improving the Return Value of
Erase-Like Algorithms" and so fail to preserve the useful information
returned by the members of the linked list containers.

I expect that to get fixed as a defect. If you have time and
motivation, I think we should make that change proactively in
libstdc++. The Library Fundamentals versions can continue to return
void, but the ones in namespace std can return the number of elements
removed.


I committed essentially what I started with (attached) as a baseline.

I would like to change the return as you suggest in another patch.

It seems to me that the intent of UCE is to have the same API for all 
containers.


So all erase_if would have size_type returns, including vector, string, 
deque.  Not a problem as those are const time.


It looks like the node erasure tool needs to maintain a count of erased 
nodes.  (it can't use erase(KeyT k) that returns a count since it 
involves a predicate rather than key compare.  Too bad there aren't 
'size_t erase_if(Pred)' members.)  No biggie - the complexity isn't 
changed by keeping count.


Holy crap.  i just noticed that *set/*map don't have plain erase() only 
erase_if()!


I need to implement final: 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1209r0.html 
before I do anything.  Both for experimental and std.


Ed




2018-11-28  Edward Smith-Rowland  <3dw...@verizon.net>

Implement uniform container erasure for C++20.
* include/Makefile.am: Move erase_if.h.
* include/Makefile.in: Move erase_if.h.
* include/experimental/bits/erase_if.h: Move ...
* include/bits/erase_if.h: ... here.
* include/experimental/map: Move erase_if.h.
* include/experimental/set: Move erase_if.h.
* include/experimental/unordered_map: Move erase_if.h.
* include/experimental/unordered_set: Move erase_if.h.
* include/std/deque (erase_if, erase): New functions.
* include/std/forward_list: Ditto.
* include/std/list: Ditto.
* include/std/map: Ditto.
* include/std/set: Ditto.
* include/std/string: Ditto.
* include/std/unordered_map: Ditto.
* include/std/unordered_set: Ditto.
* include/std/vector: Ditto.
* testsuite/21_strings/basic_string/erasure.cc: New test.
* testsuite/23_containers/deque/erasure.cc: New test.
* testsuite/23_containers/forward_list/erasure.cc: New test.
* testsuite/23_containers/list/erasure.cc: New test.
* testsuite/23_containers/map/erasure.cc: New test.
* testsuite/23_containers/set/erasure.cc: New test.
* testsuite/23_containers/unordered_map/erasure.cc: New test.
* testsuite/23_containers/unordered_set/erasure.cc: New test.
* testsuite/23_containers/vector/erasure.cc: New test.

Index: include/Makefile.am
===
--- include/Makefile.am (revision 266566)
+++ include/Makefile.am (working copy)
@@ -106,6 +106,7 @@
${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/deque.tcc \
${bits_srcdir}/enable_special_members.h \
+   ${bits_srcdir}/erase_if.h \
${bits_srcdir}/forward_list.h \
${bits_srcdir}/forward_list.tcc \
${bits_srcdir}/fs_dir.h \
@@ -710,7 +711,6 @@
 experimental_bits_srcdir = ${glibcxx_srcdir}/include/experimental/bits
 experimental_bits_builddir = ./experimental/bits
 experimental_bits_headers = \
-   ${experimental_bits_srcdir}/erase_if.h \
${experimental_bits_srcdir}/lfts_config.h \
${experimental_bits_srcdir}/net.h \
${experimental_bits_srcdir}/shared_ptr.h \
Index: include/Makefile.in
===
--- include/Makefile.in (revision 266566)
+++ include/Makefile.in (working copy)
@@ -449,6 +449,7 @@
${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/deque.tcc \
${bits_srcdir}/enable_special_members.h \
+   ${bits_srcdir}/erase_if.h \
${bits_srcdir}/forward_list.h \
${bits_srcdir}/forward_list.tcc \
${bits_srcdir}/fs_dir.h \
@@ -1052,7 +1053,6 @@
 experime

[PATCH, libstdc++] Uniform container erasure for c++20.

2018-11-24 Thread Ed Smith-Rowland

All,

I's very late but uniform container erasure is, I think, the last little 
tidbit to graduate from fundamentals/v2 to std at the last meeting.  I 
think it would be a shame not to nudge this into gcc-9.  The routines 
are very short so I just copied them. Ditto the testcases (with 
adjustments).  The node erasure tool was moved from experimental to 
std/bits and adjustments made to affected *set/*map headers.


The experimental code has been in our tree since 2015.

This builds and tests clean on x86_64-linux.

Ed


Index: include/Makefile.am
===
--- include/Makefile.am (revision 266430)
+++ include/Makefile.am (working copy)
@@ -106,6 +106,7 @@
${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/deque.tcc \
${bits_srcdir}/enable_special_members.h \
+   ${bits_srcdir}/erase_if.h \
${bits_srcdir}/forward_list.h \
${bits_srcdir}/forward_list.tcc \
${bits_srcdir}/fs_dir.h \
@@ -710,7 +711,6 @@
 experimental_bits_srcdir = ${glibcxx_srcdir}/include/experimental/bits
 experimental_bits_builddir = ./experimental/bits
 experimental_bits_headers = \
-   ${experimental_bits_srcdir}/erase_if.h \
${experimental_bits_srcdir}/lfts_config.h \
${experimental_bits_srcdir}/net.h \
${experimental_bits_srcdir}/shared_ptr.h \
Index: include/Makefile.in
===
--- include/Makefile.in (revision 266430)
+++ include/Makefile.in (working copy)
@@ -449,6 +449,7 @@
${bits_srcdir}/cpp_type_traits.h \
${bits_srcdir}/deque.tcc \
${bits_srcdir}/enable_special_members.h \
+   ${bits_srcdir}/erase_if.h \
${bits_srcdir}/forward_list.h \
${bits_srcdir}/forward_list.tcc \
${bits_srcdir}/fs_dir.h \
@@ -1052,7 +1053,6 @@
 experimental_bits_srcdir = ${glibcxx_srcdir}/include/experimental/bits
 experimental_bits_builddir = ./experimental/bits
 experimental_bits_headers = \
-   ${experimental_bits_srcdir}/erase_if.h \
${experimental_bits_srcdir}/lfts_config.h \
${experimental_bits_srcdir}/net.h \
${experimental_bits_srcdir}/shared_ptr.h \
Index: include/bits/erase_if.h
===
--- include/bits/erase_if.h (revision 266430)
+++ include/bits/erase_if.h (working copy)
@@ -1,4 +1,4 @@
-//  -*- C++ -*-
+//  -*- C++ -*-
 
 // Copyright (C) 2015-2018 Free Software Foundation, Inc.
 //
@@ -22,27 +22,22 @@
 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // .
 
-/** @file experimental/bits/erase_if.h
+/** @file bits/erase_if.h
  *  This is an internal header file, included by other library headers.
  *  Do not attempt to use it directly.
  */
 
-#ifndef _GLIBCXX_EXPERIMENTAL_ERASE_IF_H
-#define _GLIBCXX_EXPERIMENTAL_ERASE_IF_H 1
+#ifndef _GLIBCXX_ERASE_IF_H
+#define _GLIBCXX_ERASE_IF_H 1
 
 #pragma GCC system_header
 
 #if __cplusplus >= 201402L
-#include 
 
 namespace std
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-namespace experimental
-{
-inline namespace fundamentals_v2
-{
   namespace __detail
   {
 template
@@ -59,8 +54,6 @@
}
   }
   } // namespace __detail
-} // inline namespace fundamentals_v2
-} // namespace experimental
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
@@ -67,4 +60,4 @@
 
 #endif // C++14
 
-#endif // _GLIBCXX_EXPERIMENTAL_ERASE_IF_H
+#endif // _GLIBCXX_ERASE_IF_H
Index: include/experimental/bits/erase_if.h
===
--- include/experimental/bits/erase_if.h(revision 266430)
+++ include/experimental/bits/erase_if.h(nonexistent)
@@ -1,70 +0,0 @@
-//  -*- C++ -*-
-
-// Copyright (C) 2015-2018 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
-// .
-
-/** @file experimental/bits/erase_if.h
- *  This is an internal header file, included by other library headers.
- *  Do not attempt 

Re: [PATCH, libstdc++] Implement P0415 More constexpr for std::complex.

2018-11-20 Thread Ed Smith-Rowland

On 11/19/18 6:13 AM, Jonathan Wakely wrote:

On 16/11/18 19:39 -0500, Ed Smith-Rowland wrote:

@@ -322,67 +323,43 @@
  //@{
  ///  Return new complex value @a x plus @a y.
  template
-    inline complex<_Tp>
+    inline _GLIBCXX20_CONSTEXPR complex<_Tp>
    operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
-    {
-  complex<_Tp> __r = __x;
-  __r += __y;
-  return __r;
-    }
+    { return complex<_Tp>(__x.real() + __y.real(), __x.imag() + 
__y.imag()); }


Is this change (and all the similar ones) really needed?

Doesn't the fact that all the constructors and member operators of
std::complex mean that the original definition is also valid in a
constexpr function?

These changes are rolled back. Sorry.

@@ -1163,50 +1143,43 @@
#endif

  template
-    complex&
+    _GLIBCXX20_CONSTEXPR complex&
    operator=(const complex<_Tp>&  __z)
{
-  __real__ _M_value = __z.real();
-  __imag__ _M_value = __z.imag();
+  _M_value = __z.__rep();


These changes look OK, but I wonder if we shouldn't ask the compiler
to make it possible to use __real__ and __imag__ in constexpr
functions instead.

I assume it doesn't, and that's why you made this change. But if it
Just Worked, and the other changes I commented on above are also
unnecessary, then this patch would *mostly* just be adding
_GLIBCXX20_CONSTEXPR which is OK for stage 3 (as it doesn't affect any
dialects except C++2a).


Yes, this is the issue.  I agree that constexpr _real__, __imag__would 
be better.


Do you have any idea where this change would be?  I grepped around a 
little and couldn't figure it out.  if you don't I'll look more.


Actually, looking at constexpr.c it looks like the old way ought to work...

OK, plain assignment works but not the others.  Interesting.




@@ -1872,7 +1831,7 @@
    { return _Tp(); }

  template
-    inline typename __gnu_cxx::__promote<_Tp>::__type
+    _GLIBCXX_CONSTEXPR inline typename 
__gnu_cxx::__promote<_Tp>::__type


This should be _GLIBCXX20_CONSTEXPR.

Done.
Index: 
testsuite/26_numerics/complex/comparison_operators/more_constexpr.cc

===
--- 
testsuite/26_numerics/complex/comparison_operators/more_constexpr.cc 
(nonexistent)
+++ 
testsuite/26_numerics/complex/comparison_operators/more_constexpr.cc 
(working copy)

@@ -0,0 +1,51 @@
+// { dg-do compile { target c++2a } }


All the tests with { target c++2a} should also have:

// { dg-options "-std=gnu++2a" }

Because otherwise they are skipped by default, and only get run when
RUNTESTFLAGS explicitly includes something like
--target_board=unix/-std=gnu++2a

The dg-options needs to come first, or it doesn't apply before the
check for { target c++2a }.


Thank you, done.

Updated patch attached.  I'd like to understand why

    __real__ _M_value += __z.real();

doesn't work though.

Ed


Index: include/std/complex
===
--- include/std/complex (revision 266251)
+++ include/std/complex (working copy)
@@ -70,10 +70,11 @@
   ///  Return phase angle of @a z.
   template _Tp arg(const complex<_Tp>&);
   ///  Return @a z magnitude squared.
-  template _Tp norm(const complex<_Tp>&);
+  template _Tp _GLIBCXX20_CONSTEXPR norm(const complex<_Tp>&);
 
   ///  Return complex conjugate of @a z.
-  template complex<_Tp> conj(const complex<_Tp>&);
+  template
+_GLIBCXX20_CONSTEXPR complex<_Tp> conj(const complex<_Tp>&);
   ///  Return complex with magnitude @a rho and angle @a theta.
   template complex<_Tp> polar(const _Tp&, const _Tp& = 0);
 
@@ -169,18 +170,18 @@
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // DR 387. std::complex over-encapsulated.
-  void
+  _GLIBCXX20_CONSTEXPR void
   real(_Tp __val) { _M_real = __val; }
 
-  void
+  _GLIBCXX20_CONSTEXPR void
   imag(_Tp __val) { _M_imag = __val; }
 
   /// Assign a scalar to this complex number.
-  complex<_Tp>& operator=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator=(const _Tp&);
 
   /// Add a scalar to this complex number.
   // 26.2.5/1
-  complex<_Tp>&
+  _GLIBCXX20_CONSTEXPR complex<_Tp>&
   operator+=(const _Tp& __t)
   {
_M_real += __t;
@@ -189,7 +190,7 @@
 
   /// Subtract a scalar from this complex number.
   // 26.2.5/3
-  complex<_Tp>&
+  _GLIBCXX20_CONSTEXPR complex<_Tp>&
   operator-=(const _Tp& __t)
   {
_M_real -= __t;
@@ -197,30 +198,30 @@
   }
 
   /// Multiply this complex number by a scalar.
-  complex<_Tp>& operator*=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator*=(const _Tp&);
   /// Divide this complex num

Re: [PATCH, libstdc++] Implement P0415 More constexpr for std::complex.

2018-11-16 Thread Ed Smith-Rowland

On 11/16/18 3:53 PM, Ed Smith-Rowland wrote:

On 11/16/18 12:38 PM, Daniel Krügler wrote:

Am Fr., 16. Nov. 2018 um 18:13 Uhr schrieb Ed Smith-Rowland
<3dw...@verizon.net>:

Greetings,

This is late but I wanted to put it out there just to finish a thing.

It's fairly straightforward constexpr of operators and some simple
functions for std::complex.

The only thing that jumped out was the norm function.  We had this:

  struct _Norm_helper
  {
    template
  static inline _Tp _S_do_it(const complex<_Tp>& __z)
  {
    _Tp __res = std::abs(__z);
    return __res * __res;
  }
  };

Since abs can't be made constexpr for complex since it involves sqrt 
(It
probably could but that's another story) I had to fall back to the 
x^2 +

y^2.  I don't know who that will bother.  This version should be faster
and I can't think of any useful trustworthy difference numerically
either in terms of accuracy of stability.

Barring any feedback on that I'll clean it up and maybe rename my tests
from constexpr_all_the_things.cc to more_constexpr.cc ;-)

It builds and tests cleanly on x86_64-linux.

Hmmh, according to the recent working draft the following complex
functions are *not* constexpr:

arg, proj

So, shouldn't their new C++20-constexpr specifiers be added
conditionally (In the sense of gcc extensions)?

- Daniel

I did not see that those were not constexpr.  I guess arg needs atan2 
and proj


I'll remove the constexpr on those and adjust everything.

Thank you.

Ed


All,

Here is the cleaned up, conformant patch.

Builds and tests cleanly on x86_64-linux.

Is this OK or should I really wait?

Ed



2018-11-17  Edward Smith-Rowland  <3dw...@verizon.net>

Implement P0415 More constexpr for std::complex.
* include/std/complex (conj(complex), norm(complex)): Constexpr;
(real(Tp), imag(Tp)): Constexpr;
(operator@=(Tp), operator@=(complex)): Constexpr;
(operator@(Tp,complex), operator@(complex,Tp)
operator@(complex,complex)): Constexpr.
* testsuite/26_numerics/complex/comparison_operators/
more_constexpr.cc: New test.
* testsuite/26_numerics/complex/operators/more_constexpr.cc: New test.
* testsuite/26_numerics/complex/requirements/
more_constexpr.cc: New test.
* testsuite/26_numerics/complex/value_operations/
more_constexpr.cc: New test.
* testsuite/26_numerics/headers/complex/synopsis.cc:
Add _GLIBCXX20_CONSTEXPR to applicable operators; Add missing proj().
Index: include/std/complex
===
--- include/std/complex (revision 266189)
+++ include/std/complex (working copy)
@@ -70,10 +70,11 @@
   ///  Return phase angle of @a z.
   template _Tp arg(const complex<_Tp>&);
   ///  Return @a z magnitude squared.
-  template _Tp norm(const complex<_Tp>&);
+  template _Tp _GLIBCXX20_CONSTEXPR norm(const complex<_Tp>&);
 
   ///  Return complex conjugate of @a z.
-  template complex<_Tp> conj(const complex<_Tp>&);
+  template
+_GLIBCXX20_CONSTEXPR complex<_Tp> conj(const complex<_Tp>&);
   ///  Return complex with magnitude @a rho and angle @a theta.
   template complex<_Tp> polar(const _Tp&, const _Tp& = 0);
 
@@ -169,18 +170,18 @@
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // DR 387. std::complex over-encapsulated.
-  void
+  _GLIBCXX20_CONSTEXPR void
   real(_Tp __val) { _M_real = __val; }
 
-  void
+  _GLIBCXX20_CONSTEXPR void
   imag(_Tp __val) { _M_imag = __val; }
 
   /// Assign a scalar to this complex number.
-  complex<_Tp>& operator=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator=(const _Tp&);
 
   /// Add a scalar to this complex number.
   // 26.2.5/1
-  complex<_Tp>&
+  _GLIBCXX20_CONSTEXPR complex<_Tp>&
   operator+=(const _Tp& __t)
   {
_M_real += __t;
@@ -189,7 +190,7 @@
 
   /// Subtract a scalar from this complex number.
   // 26.2.5/3
-  complex<_Tp>&
+  _GLIBCXX20_CONSTEXPR complex<_Tp>&
   operator-=(const _Tp& __t)
   {
_M_real -= __t;
@@ -197,30 +198,30 @@
   }
 
   /// Multiply this complex number by a scalar.
-  complex<_Tp>& operator*=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator*=(const _Tp&);
   /// Divide this complex number by a scalar.
-  complex<_Tp>& operator/=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator/=(const _Tp&);
 
   // Let the compiler synthesize the copy assignment operator
 #if __cplusplus >= 201103L
-  complex& operator=(const complex&) = default;
+  _GLIBCXX20_CONSTEXPR complex& operator=(const complex&) = default;

Re: [PATCH, PR libstdc++/83566] - cyl_bessel_j returns wrong result for x>1000

2018-11-16 Thread Ed Smith-Rowland

On 11/16/18 5:32 PM, Michele Pezzutti wrote:

Hi.

My Copyright assignment process is complete (done in Feb 2018).

Michele


On 16/11/2018 18:23, Ed Smith-Rowland wrote:

All,

This patch has been in my queue for a while.

I believe it is waiting on Copyright assignment for Michele. Is this 
still true?


Ed





Excellent! Unless anyone has any objections I'll push this tomorrow.

Ed




Re: [PATCH, libstdc++] Implement P0415 More constexpr for std::complex.

2018-11-16 Thread Ed Smith-Rowland

On 11/16/18 12:38 PM, Daniel Krügler wrote:

Am Fr., 16. Nov. 2018 um 18:13 Uhr schrieb Ed Smith-Rowland
<3dw...@verizon.net>:

Greetings,

This is late but I wanted to put it out there just to finish a thing.

It's fairly straightforward constexpr of operators and some simple
functions for std::complex.

The only thing that jumped out was the norm function.  We had this:

  struct _Norm_helper
  {
template
  static inline _Tp _S_do_it(const complex<_Tp>& __z)
  {
_Tp __res = std::abs(__z);
return __res * __res;
  }
  };

Since abs can't be made constexpr for complex since it involves sqrt (It
probably could but that's another story) I had to fall back to the x^2 +
y^2.  I don't know who that will bother.  This version should be faster
and I can't think of any useful trustworthy difference numerically
either in terms of accuracy of stability.

Barring any feedback on that I'll clean it up and maybe rename my tests
from constexpr_all_the_things.cc to more_constexpr.cc ;-)

It builds and tests cleanly on x86_64-linux.

Hmmh, according to the recent working draft the following complex
functions are *not* constexpr:

arg, proj

So, shouldn't their new C++20-constexpr specifiers be added
conditionally (In the sense of gcc extensions)?

- Daniel

I did not see that those were not constexpr.  I guess arg needs atan2 
and proj


I'll remove the constexpr on those and adjust everything.

Thank you.

Ed




[PATCH, PR libstdc++/83566] - cyl_bessel_j returns wrong result for x>1000

2018-11-16 Thread Ed Smith-Rowland

All,

This patch has been in my queue for a while.

I believe it is waiting on Copyright assignment for Michele. Is this 
still true?


Ed



2018-11-16  Michele Pezzutti 
Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/83566 - cyl_bessel_j returns wrong result for x>1000
for high orders.
* include/tr1/bessel_function.tcc: Perform no fewer than nu/2 iterations
of the asymptotic series (nu is the Bessel order).
* testsuite/tr1/5_numerical_facilities/special_functions/
09_cyl_bessel_j/check_value.cc: Add tests at nu=100, 1000<=x<=2000.
* testsuite/tr1/5_numerical_facilities/special_functions/   
11_cyl_neumann/check_value.cc: Ditto.
* testsuite/special_functions/08_cyl_bessel_j/check_value.cc: Ditto.
* testsuite/special_functions/10_cyl_neumann/check_value.cc: Ditto.
Index: include/tr1/bessel_function.tcc
===
--- include/tr1/bessel_function.tcc (revision 266189)
+++ include/tr1/bessel_function.tcc (working copy)
@@ -27,6 +27,10 @@
  *  Do not attempt to use it directly. @headername{tr1/cmath}
  */
 
+/* __cyl_bessel_jn_asymp adapted from GNU GSL version 2.4 specfunc/bessel_j.c
+ * Copyright (C) 1996-2003 Gerard Jungman
+ */
+
 //
 // ISO C++ 14882 TR1: 5.2  Special functions
 //
@@ -358,24 +362,51 @@
 void
 __cyl_bessel_jn_asymp(_Tp __nu, _Tp __x, _Tp & __Jnu, _Tp & __Nnu)
 {
-  const _Tp __mu   = _Tp(4) * __nu * __nu;
-  const _Tp __mum1 = __mu - _Tp(1);
-  const _Tp __mum9 = __mu - _Tp(9);
-  const _Tp __mum25 = __mu - _Tp(25);
-  const _Tp __mum49 = __mu - _Tp(49);
-  const _Tp __xx = _Tp(64) * __x * __x;
-  const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx)
-* (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx));
-  const _Tp __Q = __mum1 / (_Tp(8) * __x)
-* (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx));
+  const _Tp __mu = _Tp(4) * __nu * __nu;
+  const _Tp __8x = _Tp(8) * __x;
 
+  _Tp __P = _Tp(0);
+  _Tp __Q = _Tp(0);
+
+  _Tp __k = _Tp(0);
+  _Tp __term = _Tp(1);
+
+  int __epsP = 0;
+  int __epsQ = 0;
+
+  _Tp __eps = std::numeric_limits<_Tp>::epsilon();
+
+  do
+{
+  __term *= (__k == 0
+ ? _Tp(1)
+ : -(__mu - (2 * __k - 1) * (2 * __k - 1)) / (__k * __8x));
+
+  __epsP = std::abs(__term) < __eps * std::abs(__P);
+  __P += __term;
+
+  __k++;
+
+  __term *= (__mu - (2 * __k - 1) * (2 * __k - 1)) / (__k * __8x);
+  __epsQ = std::abs(__term) < __eps * std::abs(__Q);
+  __Q += __term;
+
+  if (__epsP && __epsQ && __k > (__nu / 2.))
+break;
+
+  __k++;
+}
+  while (__k < 1000);
+
   const _Tp __chi = __x - (__nu + _Tp(0.5L))
-* __numeric_constants<_Tp>::__pi_2();
+ * __numeric_constants<_Tp>::__pi_2();
+
   const _Tp __c = std::cos(__chi);
   const _Tp __s = std::sin(__chi);
 
   const _Tp __coef = std::sqrt(_Tp(2)
  / (__numeric_constants<_Tp>::__pi() * __x));
+
   __Jnu = __coef * (__c * __P - __s * __Q);
   __Nnu = __coef * (__s * __P + __c * __Q);
 
Index: 
testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
===
--- 
testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
   (revision 266189)
+++ 
testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
   (working copy)
@@ -698,6 +698,39 @@
 };
 const double toler026 = 1.0006e-11;
 
+// Test data for nu=100.
+// max(|f - f_GSL|): 3.9438938226332709e-14 at index 19
+// max(|f - f_GSL| / |f_GSL|): 2.0193411077170867e-11
+// mean(f - f_GSL): 1.6682360684660055e-15
+// variance(f - f_GSL): 5.3274331668346898e-28
+// stddev(f - f_GSL): 2.3081232997469372e-14
+const testcase_cyl_bessel_j
+data027[21] =
+{
+  {  1.1676135007789573e-02, 100., 1000., 0.0 
},
+  { -1.1699854778025796e-02, 100., 1100., 0.0 
},
+  { -2.2801483405083697e-02, 100., 1200., 0.0 
},
+  { -1.6973500787373915e-02, 100., 1300., 0.0 
},
+  { -1.4154528803481308e-03, 100., 1400., 0.0 
},
+  {  1.726584495232e-02, 100., 1500., 0.0 
},
+  {  1.9802562020148559e-02, 100., 1600., 0.0 
},
+  {  1.6129771279838816e-02, 100., 1700., 0.0 
},
+  {  5.3753369281536031e-03, 100., 1800., 0.0 
},
+  { -6.9238868725645785e-03, 100., 1900., 0.0 

[PATCH, libstdc++] Implement P0415 More constexpr for std::complex.

2018-11-16 Thread Ed Smith-Rowland

Greetings,

This is late but I wanted to put it out there just to finish a thing.

It's fairly straightforward constexpr of operators and some simple 
functions for std::complex.


The only thing that jumped out was the norm function.  We had this:

    struct _Norm_helper
    {
  template
    static inline _Tp _S_do_it(const complex<_Tp>& __z)
    {
  _Tp __res = std::abs(__z);
  return __res * __res;
    }
    };

Since abs can't be made constexpr for complex since it involves sqrt (It 
probably could but that's another story) I had to fall back to the x^2 + 
y^2.  I don't know who that will bother.  This version should be faster 
and I can't think of any useful trustworthy difference numerically 
either in terms of accuracy of stability.


Barring any feedback on that I'll clean it up and maybe rename my tests 
from constexpr_all_the_things.cc to more_constexpr.cc ;-)


It builds and tests cleanly on x86_64-linux.

Ed




2018-11-16  Edward Smith-Rowland  <3dw...@verizon.net>

Implement P0415 More constexpr for std::complex.
* include/std/complex (proj(), norm(), conj(), arg()): Constexpr.
(real(Tp), imag(Tp)): Constexpr.
(operator@=(Tp), operator@=(complex)): Constexpr.
(operator@(Tp,complex), operator@(complex,Tp)
operator@(complex,complex)): Constexpr.
* testsuite/26_numerics/complex/comparison_operators/
constexpr_all_the_things.cc: New test.
* testsuite/26_numerics/complex/operators/
constexpr_all_the_things.cc: New test.
* testsuite/26_numerics/complex/requirements/
constexpr_all_the_things.cc: New test.
* testsuite/26_numerics/complex/value_operations/
constexpr_all_the_things.cc: New test.
* testsuite/26_numerics/headers/complex/synopsis.cc:
Add _GLIBCXX20_CONSTEXPR to applicable operators; Add missing proj().
Index: include/std/complex
===
--- include/std/complex (revision 266189)
+++ include/std/complex (working copy)
@@ -68,12 +68,13 @@
   ///  Return magnitude of @a z.
   template _Tp abs(const complex<_Tp>&);
   ///  Return phase angle of @a z.
-  template _Tp arg(const complex<_Tp>&);
+  template _Tp _GLIBCXX20_CONSTEXPR arg(const complex<_Tp>&);
   ///  Return @a z magnitude squared.
-  template _Tp norm(const complex<_Tp>&);
+  template _Tp _GLIBCXX20_CONSTEXPR norm(const complex<_Tp>&);
 
   ///  Return complex conjugate of @a z.
-  template complex<_Tp> conj(const complex<_Tp>&);
+  template
+_GLIBCXX20_CONSTEXPR complex<_Tp> conj(const complex<_Tp>&);
   ///  Return complex with magnitude @a rho and angle @a theta.
   template complex<_Tp> polar(const _Tp&, const _Tp& = 0);
 
@@ -169,18 +170,18 @@
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
   // DR 387. std::complex over-encapsulated.
-  void
+  _GLIBCXX20_CONSTEXPR void
   real(_Tp __val) { _M_real = __val; }
 
-  void
+  _GLIBCXX20_CONSTEXPR void
   imag(_Tp __val) { _M_imag = __val; }
 
   /// Assign a scalar to this complex number.
-  complex<_Tp>& operator=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator=(const _Tp&);
 
   /// Add a scalar to this complex number.
   // 26.2.5/1
-  complex<_Tp>&
+  _GLIBCXX20_CONSTEXPR complex<_Tp>&
   operator+=(const _Tp& __t)
   {
_M_real += __t;
@@ -189,7 +190,7 @@
 
   /// Subtract a scalar from this complex number.
   // 26.2.5/3
-  complex<_Tp>&
+  _GLIBCXX20_CONSTEXPR complex<_Tp>&
   operator-=(const _Tp& __t)
   {
_M_real -= __t;
@@ -197,30 +198,30 @@
   }
 
   /// Multiply this complex number by a scalar.
-  complex<_Tp>& operator*=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator*=(const _Tp&);
   /// Divide this complex number by a scalar.
-  complex<_Tp>& operator/=(const _Tp&);
+  _GLIBCXX20_CONSTEXPR complex<_Tp>& operator/=(const _Tp&);
 
   // Let the compiler synthesize the copy assignment operator
 #if __cplusplus >= 201103L
-  complex& operator=(const complex&) = default;
+  _GLIBCXX20_CONSTEXPR complex& operator=(const complex&) = default;
 #endif
 
   /// Assign another complex number to this one.
   template
-complex<_Tp>& operator=(const complex<_Up>&);
+_GLIBCXX20_CONSTEXPR complex<_Tp>& operator=(const complex<_Up>&);
   /// Add another complex number to this one.
   template
-complex<_Tp>& operator+=(const complex<_Up>&);
+_GLIBCXX20_CONSTEXPR complex<_Tp>& operator+=(const complex<_Up>&);
   /// Subtract another complex number from this one.
   template
-complex<_Tp>& operator-=(const complex<_Up>&);
+_GLIBCXX20_CONSTEXPR complex<_Tp>& operator-=(const complex<_Up>&);
   /// Multiply this complex number by another.
   template
-complex<_Tp>& operator*=(const complex<_Up>&);
+

Re: [PATCH libquadmath/PR68686]

2018-11-05 Thread Ed Smith-Rowland

On 11/5/18 1:19 PM, Joseph Myers wrote:

On Sun, 4 Nov 2018, Ed Smith-Rowland wrote:


I looked in glibc.  Unfortunately, I see how they have the same mistake:
glibc/math/w_tgammal_compat.c:
     long double
     __tgammal(long double x)
     {
         int local_signgam;
         long double y = __ieee754_gammal_r(x,_signgam);
     ...
     return local_signgam < 0 ? - y : y;
     }
I'm very sure this is where tgammaq came from.
Ditto for glibc/math/w_tgamma_compat.c and glibc/math/w_tgammaf_compat.c.

No, that's not a mistake.  __ieee754_gammal_r returns +/- the gamma
function and sets the integer pointed to by the second argument to
indicate whether to negate the result.  (This isn't a particularly good
interface design for tgamma, as opposed to lgamma; unfortunately
__gammal_r_finite, with this interface, is a public ABI.)

Excellent, I missed the replacement of  expq (lgammaq (x)) with the 
re-entrant lgamma with the good sign.

Thank you.  I'll let someone else check this off ;-)
FWIW, I'd like to see C++ at least return narrow types like
template
  struct lgamma_t
  {
    _Tp log_abs_gamma; // O something less verbose.
    int sign; // Maybe try for same size as _Tp.
  };
C could do something like also. That's a discussion for another forum.



Re: [PATCH libquadmath/PR68686]

2018-11-04 Thread Ed Smith-Rowland

On 11/3/18 10:09 PM, Jeff Law wrote:

On 10/23/18 7:45 PM, Ed Smith-Rowland wrote:

Greetings,

This is an almost trivial patch to get the correct sign for tgammaq.

I don't have a testcase as I don't know where to put one.

OK?

Ed Smith-Rowland



tgammaq.CL

2018-10-24  Edward Smith-Rowland  <3dw...@verizon.net>

PR libquadmath/68686
* math/tgammaq.c: Correct sign for negative argument.

I don't have the relevant background to evaluate this for correctness.
Can you refer back to any kind of documentation which indicates what the
sign of the return value ought to be?

Alternately, if you can point to the relevant code in glibc that handles
the resultant sign, that'd be useful too.

Note that Joseph's follow-up doesn't touch on the gamma problem AFAICT,
but instead touches on the larger issues around trying to keep the
quadmath implementations between glibc and gcc more in sync.

Jeff


I've looked at glibc lgamma, in particular signgam and I think those DTRT:


I'm pretty sure the lgamma that write to global signgam and the 
lgamma_r(x, int *signgam) DTRT.


The various __lgamma_neg* DTRT:

__lgamma_negX (REALTYPE x, int *signgamp)
{
  /* Determine the half-integer region X lies in, handle exact
 integers and determine the sign of the result.  */
  int i = __floorl (-2 * x);
  if ((i & 1) == 0 && i == -2 * x)
    return 1.0L / 0.0L;
  long double xn = ((i & 1) == 0 ? -i / 2 : (-i - 1) / 2);
  i -= 4;
  *signgamp = ((i & 2) == 0 ? -1 : 1);
...

I think the various e_lgammaX_r.c are good too:

  if (se & 0x8000)
    {
  if (x < -2.0L && x > -33.0L)
    return __lgamma_negl (x, signgamp);
  t = sin_pi (x);
  if (t == zero)
    return one / fabsl (t);    /* -integer */
  nadj = __ieee754_logl (pi / fabsl (t * x));
  if (t < zero)
    *signgamp = -1;
  x = -x;
    }

I *do* think a couple tests should be added to test-signgam-*.c to test 
alternation of signs:

  signgam = 123;                        \
  c = FUNC (b);                        \
  if (signgam == 1)                        \

    puts ("PASS: " #FUNC " (-1.5) setting signgam");    \

  else                            \
    {                            \
      puts ("FAIL: " #FUNC " (-1.5) setting signgam");    \
      result = 1;                        \
    }                            \

Add to test lgamma_negX code paths...
  signgam = 123;                        \
  c = FUNC (b);                        \
  if (signgam == -1)                    \
    puts ("PASS: " #FUNC " (-34.5) setting signgam");    \
  else                            \
    {                            \
      puts ("FAIL: " #FUNC " (-34.5) setting signgam"); \
      result = 1;                        \
    }                            \
  signgam = 123;                        \
  c = FUNC (b);                        \
  if (signgam == 1)                        \
    puts ("PASS: " #FUNC " (-35.5) setting signgam");    \
  else                            \
    {                            \
      puts ("FAIL: " #FUNC " (-35.5) setting signgam"); \
      result = 1;                        \
    }                            \


I've not dealt with glibc directly.  Do I need separate Copyright and 
all that?  Is it similar to gcc in terms of devel?





Re: [PATCH libquadmath/PR68686]

2018-11-04 Thread Ed Smith-Rowland

On 11/3/18 10:09 PM, Jeff Law wrote:

On 10/23/18 7:45 PM, Ed Smith-Rowland wrote:

Greetings,

This is an almost trivial patch to get the correct sign for tgammaq.

I don't have a testcase as I don't know where to put one.

OK?

Ed Smith-Rowland



tgammaq.CL

2018-10-24  Edward Smith-Rowland  <3dw...@verizon.net>

PR libquadmath/68686
* math/tgammaq.c: Correct sign for negative argument.

I don't have the relevant background to evaluate this for correctness.
Can you refer back to any kind of documentation which indicates what the
sign of the return value ought to be?

Alternately, if you can point to the relevant code in glibc that handles
the resultant sign, that'd be useful too.

Note that Joseph's follow-up doesn't touch on the gamma problem AFAICT,
but instead touches on the larger issues around trying to keep the
quadmath implementations between glibc and gcc more in sync.

Jeff

Thank you for (re)considering this.The maths here can be read from a 
very good NIST website:


For the functional formulas referred to below - https://dlmf.nist.gov/5.5

For cool pictures - https://dlmf.nist.gov/5.3#i
(Aside: the reciprocal gamma function is entire - possessing no poles or 
other analytic complications anywhere in the complex plane.  A rgamma 
function might be a nice addition to the C family and to TS 18661-1 for 
that matter.)


For a table of extrema (Table 5.4.1) - https://dlmf.nist.gov/5.4#iii
These would be nice tests for accuracy as well as sign.

TL;DR:
==

Either follow the factorial-like recursion Gamma(x+1) = x Gamma(x) [DLMF 
5.5.1] backwards:

    Gamma(x-1) = Gamma(x) / (x-1)
Given that Gamma(x) is positive for x > 0 this will give alternating 
negative signs if you start with, say, x=1/2 and keep going.

A cooler formula is [DLMF 5.5.3]:
    Gamma(x) Gamma(1-x) = pi / sin(pi x)
Start with x = 3/2 and continue with higher odd half integers to see the 
sign alternation.


GLibC
=
I looked in glibc.  Unfortunately, I see how they have the same mistake:
glibc/math/w_tgammal_compat.c:
    long double
    __tgammal(long double x)
    {
        int local_signgam;
        long double y = __ieee754_gammal_r(x,_signgam);
    ...
    return local_signgam < 0 ? - y : y;
    }
I'm very sure this is where tgammaq came from.
Ditto for glibc/math/w_tgamma_compat.c and glibc/math/w_tgammaf_compat.c.

This fix will need to be done upstream.
Ed



[PATCH libquadmath/PR68686]

2018-10-23 Thread Ed Smith-Rowland

Greetings,

This is an almost trivial patch to get the correct sign for tgammaq.

I don't have a testcase as I don't know where to put one.

OK?

Ed Smith-Rowland


2018-10-24  Edward Smith-Rowland  <3dw...@verizon.net>

	PR libquadmath/68686
	* math/tgammaq.c: Correct sign for negative argument.
Index: libquadmath/math/tgammaq.c
===
--- libquadmath/math/tgammaq.c	(revision 265345)
+++ libquadmath/math/tgammaq.c	(working copy)
@@ -47,7 +47,9 @@
 /* x == -Inf.  According to ISO this is NaN.  */
 return x - x;
 
-  /* XXX FIXME.  */
   res = expq (lgammaq (x));
-  return signbitq (x) ? -res : res;
+  if (x > 0.0Q || ((int)(-x) & 1) == 1)
+return res;
+  else
+return -res;
 }


[[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2018-10-21 Thread Ed Smith-Rowland

All,

This patch implements C++2a proposal P0330R2 Literal Suffixes for 
ptrdiff_t and size_t*.  It's not official yet but looks very likely to 
pass.  It is incomplete because I'm looking for some opinions. 9We also 
might wait 'till it actually passes).


This paper takes the direction of a language change rather than a 
library change through C++11 literal operators.  This was after feedback 
on that paper after a few iterations.


As coded in this patch, integer suffixes involving 'z' are errors in C 
and warnings for C++ <= 17 (in addition to the usual warning about 
implementation suffixes shadowing user-defined ones).


OTOH, the 'z' suffix is not currently legal - it can't break 
currently-correct code in any C/C++ dialect.  furthermore, I suspect the 
language direction was chosen to accommodate a similar addition to C20.


I'm thinking of making this feature available as an extension to all of 
C/C++ perhaps with appropriate pedwarn.


Opinions?

Ed Smith-Rowland

[*] http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0330r2.html


Index: gcc/c-family/c-cppbuiltin.c
===
--- gcc/c-family/c-cppbuiltin.c (revision 265343)
+++ gcc/c-family/c-cppbuiltin.c (working copy)
@@ -975,6 +975,11 @@
  cpp_define (pfile, "__cpp_structured_bindings=201606");
  cpp_define (pfile, "__cpp_variadic_using=201611");
}
+  if (cxx_dialect > cxx17)
+   {
+ /* Set feature test macros for C++2a.  */
+ cpp_define (pfile, "__cpp_ptrdiff_t_suffix=201811");
+   }
   if (flag_concepts)
cpp_define (pfile, "__cpp_concepts=201507");
   if (flag_tm)
Index: gcc/c-family/c-lex.c
===
--- gcc/c-family/c-lex.c(revision 265343)
+++ gcc/c-family/c-lex.c(working copy)
@@ -766,6 +766,14 @@
 type = ((flags & CPP_N_UNSIGNED)
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
+  else if (flags & CPP_N_PTRDIFF_T)
+{
+  /* itk refers to fundamental types not aliased size types.  */
+  if (flags & CPP_N_UNSIGNED)
+   type = size_type_node;
+  else
+   type = ptrdiff_type_node;
+}
   else
 {
   type = integer_types[itk];
Index: gcc/c-family/c.opt
===
--- gcc/c-family/c.opt  (revision 265343)
+++ gcc/c-family/c.opt  (working copy)
@@ -699,6 +699,10 @@
 C ObjC C++ ObjC++ CPP(cpp_warn_long_long) CppReason(CPP_W_LONG_LONG) 
Var(warn_long_long) Init(-1) Warning LangEnabledBy(C ObjC,Wc90-c99-compat)
 Do not warn about using \"long long\" when -pedantic.
 
+Wptrdiff_t-literals
+C ObjC C++ ObjC++ CPP(ptrdiff_t_literals) CppReason(CPP_W_PTRDIFF_T_LITERALS) 
Var(warn_ptrdiff_t_literals) Init(1) Warning LangEnabledBy(C ObjC C++ ObjC++)
+Warn when \"z\" or \"Z\" is used as a numeric literal suffix for C or C++yy, 
yy <= 17.
+
 Wmain
 C ObjC C++ ObjC++ Var(warn_main) Init(-1) Warning LangEnabledBy(C ObjC,Wall, 
2, 0)
 Warn about suspicious declarations of \"main\".
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C   (revision 265343)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C   (working copy)
@@ -17,6 +17,30 @@
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" uz(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" zu(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" Z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" UZ(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" ZU(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
 //  Namespaces are no hiding place.
 namespace Long
 {
@@ -37,6 +61,30 @@
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowe

Re: RFC: What should go in our header?

2018-06-17 Thread Ed Smith-Rowland

On 06/15/2018 11:52 AM, Jonathan Wakely wrote:

C++20 adds a  header, which should define all the library
feature test macros, as well as implementation-specific macros like
_GLIBCXX_RELEASE and __GLIBCXX__.

We should decide whether to implement  by simply including
 and then adding the feature test macros, or if we
should keep it minimal and *only* define _GLIBCXX_RELEASE and
__GLIBCXX__ and the feature tests (and then have 
include ?)

I think I prefer to make  just include .

I think we should define the feature-test macros in both  and
the relevant header (e.g. __cpp_string_view in ). We
could make everything include  and then every header would
define every feature test macro, but I don't think that's good for
portability.

My preference is implemented by the attached patch.


This is pretty much what I was looking at doing.  I say go!


While on the subject, should we just delete some of this autoconf-junk
from our c++config.h headers?

/* Name of package */
/* #undef _GLIBCXX_PACKAGE */

/* Define to the address where bug reports for this package should be 
sent. */

#define _GLIBCXX_PACKAGE_BUGREPORT ""

/* Define to the full name of this package. */
#define _GLIBCXX_PACKAGE_NAME "package-unused"

/* Define to the full name and version of this package. */
#define _GLIBCXX_PACKAGE_STRING "package-unused version-unused"

/* Define to the one symbol short name of this package. */
#define _GLIBCXX_PACKAGE_TARNAME "libstdc++"

/* Define to the home page for this package. */
#define _GLIBCXX_PACKAGE_URL ""

/* Define to the version of this package. */
#define _GLIBCXX_PACKAGE__GLIBCXX_VERSION "version-unused"

I don't have an opinion here except if this is unused cruft let's lose 
it.  I think we *are* supposed to have some project and version 
identification.  We have _GLIBCXX_* everywhere.  The folks that use 
libstdc++ *outside* of g++ might have some opinions about this too.


Ed




Re: [libstdc++, PATCH] PR libstdc++/83140 - assoc_legendre returns negated value when m is odd.

2018-05-11 Thread Ed Smith-Rowland



which always causes a failure:

+FAIL: 
tr1/5_numerical_facilities/special_functions/02_assoc_legendre/check_value.cc 
(test for excess errors)

Excess errors:
Undefined   first referenced
  symbol in file
main/usr/lib/crt1.o
ld: fatal: symbol referencing errors

+UNRESOLVED: tr1/5_numerical_facilities/special_functions/02_assoc_legendre/chec
k_value.cc compilation failed to produce executable

Please fix.

Rainer


Done with 260168.

Ed




Re: [libstdc++, PATCH] PR libstdc++/83140 - assoc_legendre returns negated value when m is odd.

2018-05-10 Thread Ed Smith-Rowland

On 05/10/2018 01:44 PM, Rainer Orth wrote:

Hi Ed,


2018-05-07  Edward Smith-Rowland  <3dw...@verizon.net>

 PR libstdc++/83140 - assoc_legendre returns negated value when m is
odd
 * include/tr1/legendre_function.tcc (__assoc_legendre_p): Add
__phase
 argument defaulted to +1.  Doxy comments on same.
 * testsuite/special_functions/02_assoc_legendre/
 check_assoc_legendre.cc: Regen.
 * testsuite/tr1/5_numerical_facilities/special_functions/
 02_assoc_legendre/check_tr1_assoc_legendre.cc: Regen.

something went badly wrong with the regeneration of this last file: both
in your attached patch and in what you checked in, the file is empty.

Rainer


I had hosed up the ChangeLog!

CL change committed as 260149.

New Log attached.

Sorry.



2018-05-10  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/83140 - assoc_legendre returns negated value when m is odd
* include/tr1/legendre_function.tcc (__assoc_legendre_p): Add __phase
argument defaulted to +1.  Doxy comments on same.
* testsuite/special_functions/02_assoc_legendre/
check_value.cc: Regen.
* testsuite/tr1/5_numerical_facilities/special_functions/
02_assoc_legendre/check_value.cc: Regen.



Quo Vadis tr1? Was: [libstdc++, PATCH] PR libstdc++/83140 - assoc_legendre returns negated value when m is odd.

2018-05-10 Thread Ed Smith-Rowland

All,


We could consider dropping the TR1 support, and just provide these
functions for ISO/IEC 29124:2010 in C++11 (or later) and for C++17.
But that decision should be taken separately, and should only happen
on trunk anyway so we need to use _Tp(+1) here.


I am in favour of splitting new versions of the special functions out of 
tr1 and into std/bits.

I personally am itching to use at least C++11 for implementation.
We have been defaulting to C++11 for, IIRC, two releases (Hence my 
-Tp{+1} slip LOL).

I have a lot of work towards this that I wanted to get into 9 anyway.

This would end the last useful thing in tr1 that's not better 
implemented elsewhere. There are certainly people using tr1. Can we 
deprecate the whole namespace?  That might be too noisy.  I think we 
should be done with maths bugs in Bugzilla pretty soon.  We should do 
whatever we decide relatively early in 9.


Ed

Also, I think 83566 should go into tr1 first because it's not a 
signature change.




Re: [libstdc++, PATCH] PR libstdc++/83140 - assoc_legendre returns negated value when m is odd.

2018-05-10 Thread Ed Smith-Rowland

On 05/09/2018 05:30 AM, Jonathan Wakely wrote:

On 07/05/18 12:39 -0400, Ed Smith-Rowland wrote:

All,

We were using a different convention for P_l^m assoc_legendre(int l, 
int m, FloatTp x)


 - the so-called Condon-Shortley convention which includes (-1)^m.  
This unfortunately is common.


This factor is taken out to match the standard.  The underlying 
__detail code has an arg that allows you to flip this


- mostly to highlight the subtle difference.

The related sph_legendre is unaffected by this (our impl and the 
standard include the C-S phase).


OK for trunk and branches?

Ed






2018-05-07  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/83140 - assoc_legendre returns negated value when m 
is odd
* include/tr1/legendre_function.tcc (__assoc_legendre_p): Add 
__phase

argument defaulted to +1.  Doxy comments on same.
* testsuite/special_functions/02_assoc_legendre/
check_assoc_legendre.cc: Regen.
* testsuite/tr1/5_numerical_facilities/special_functions/
02_assoc_legendre/check_tr1_assoc_legendre.cc: Regen.




Index: include/tr1/legendre_function.tcc
===
--- include/tr1/legendre_function.tcc    (revision 259973)
+++ include/tr1/legendre_function.tcc    (working copy)
@@ -65,7 +65,7 @@
  namespace __detail
  {
    /**
- *   @brief  Return the Legendre polynomial by recursion on order
+ *   @brief  Return the Legendre polynomial by recursion on degree
 *   @f$ l @f$.
 *
 *   The Legendre function of @f$ l @f$ and @f$ x @f$,
@@ -74,7 +74,7 @@
 * P_l(x) = \frac{1}{2^l l!}\frac{d^l}{dx^l}(x^2 - 1)^{l}
 *   @f]
 *
- *   @param  l  The order of the Legendre polynomial.  @f$l >= 
0@f$.
+ *   @param  l  The degree of the Legendre polynomial. @f$l >= 
0@f$.
 *   @param  x  The argument of the Legendre polynomial. @f$|x| 
<= 1@f$.

 */
    template
@@ -127,16 +127,19 @@
 * P_l^m(x) = (1 - x^2)^{m/2}\frac{d^m}{dx^m}P_l(x)
 *   @f]
 *
- *   @param  l  The order of the associated Legendre function.
+ *   @param  l  The degree of the associated Legendre function.
 *  @f$ l >= 0 @f$.
 *   @param  m  The order of the associated Legendre function.
 *  @f$ m <= l @f$.
 *   @param  x  The argument of the associated Legendre function.
 *  @f$ |x| <= 1 @f$.
+ *   @param  phase  The phase of the associated Legendre function.
+ *  Use -1 for the Condon-Shortley phase 
convention.

 */
    template
    _Tp
-    __assoc_legendre_p(unsigned int __l, unsigned int __m, _Tp __x)
+    __assoc_legendre_p(unsigned int __l, unsigned int __m, _Tp __x,
+   _Tp __phase = _Tp{+1})


This list-init isn't valid for C++98 i.e. when used via .
GCC seems to allow it, but Clang won't.

We could consider dropping the TR1 support, and just provide these
functions for ISO/IEC 29124:2010 in C++11 (or later) and for C++17.
But that decision should be taken separately, and should only happen
on trunk anyway so we need to use _Tp(+1) here.

OK for trunk with _Tp(+1) instead of _Tp{+1}.

Do we want to change the result of these functions on the branches?
How likely is it that changing it will affect somebody's calcuations
in a way that they don't expect from a minor release on a branch?




Here are the files applied for 260115.

As to backporting...  I did a Google and found rather more activity 
around these functions - especially legendre - than I remembered last 
time I searched.  I thought these functions were languishing, but 
apparently not.  Still low pings on ellint_3.


I *would* like to change branch 8 because it's just out.

I think I should curb my enthusiasm for branches 7 and 6.

Ed.



2018-05-10  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/83140 - assoc_legendre returns negated value when m is odd
* include/tr1/legendre_function.tcc (__assoc_legendre_p): Add __phase
argument defaulted to +1.  Doxy comments on same.
* testsuite/special_functions/02_assoc_legendre/
check_assoc_legendre.cc: Regen.
* testsuite/tr1/5_numerical_facilities/special_functions/
02_assoc_legendre/check_tr1_assoc_legendre.cc: Regen.

Index: include/tr1/legendre_function.tcc
===
--- include/tr1/legendre_function.tcc   (revision 260114)
+++ include/tr1/legendre_function.tcc   (working copy)
@@ -65,7 +65,7 @@
   namespace __detail
   {
 /**
- *   @brief  Return the Legendre polynomial by recursion on order
+ *   @brief  Return the Legendre polynomial by recursion on degree
  *   @f$ l @f$.
  * 
  *   The Legendre function of @f$ l @f$ and @f$ x @f$,
@@ -74,7 +74,7 @@
  * P_l(x) = \frac{1}{2^l l!}\frac{d^l}{dx^l}(x^2 - 1)^{l}
  *   @f]
  * 
- *   @param  l  The order of 

[libstdc++, PATCH] PR libstdc++/83140 - assoc_legendre returns negated value when m is odd.

2018-05-07 Thread Ed Smith-Rowland

All,

We were using a different convention for P_l^m assoc_legendre(int l, int 
m, FloatTp x)


 - the so-called Condon-Shortley convention which includes (-1)^m.  
This unfortunately is common.


This factor is taken out to match the standard.  The underlying __detail 
code has an arg that allows you to flip this


- mostly to highlight the subtle difference.

The related sph_legendre is unaffected by this (our impl and the 
standard include the C-S phase).


OK for trunk and branches?

Ed



2018-05-07  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/83140 - assoc_legendre returns negated value when m is odd
* include/tr1/legendre_function.tcc (__assoc_legendre_p): Add __phase
argument defaulted to +1.  Doxy comments on same.
* testsuite/special_functions/02_assoc_legendre/
check_assoc_legendre.cc: Regen.
* testsuite/tr1/5_numerical_facilities/special_functions/
02_assoc_legendre/check_tr1_assoc_legendre.cc: Regen.

Index: include/tr1/legendre_function.tcc
===
--- include/tr1/legendre_function.tcc   (revision 259973)
+++ include/tr1/legendre_function.tcc   (working copy)
@@ -65,7 +65,7 @@
   namespace __detail
   {
 /**
- *   @brief  Return the Legendre polynomial by recursion on order
+ *   @brief  Return the Legendre polynomial by recursion on degree
  *   @f$ l @f$.
  * 
  *   The Legendre function of @f$ l @f$ and @f$ x @f$,
@@ -74,7 +74,7 @@
  * P_l(x) = \frac{1}{2^l l!}\frac{d^l}{dx^l}(x^2 - 1)^{l}
  *   @f]
  * 
- *   @param  l  The order of the Legendre polynomial.  @f$l >= 0@f$.
+ *   @param  l  The degree of the Legendre polynomial.  @f$l >= 0@f$.
  *   @param  x  The argument of the Legendre polynomial.  @f$|x| <= 1@f$.
  */
 template
@@ -127,16 +127,19 @@
  * P_l^m(x) = (1 - x^2)^{m/2}\frac{d^m}{dx^m}P_l(x)
  *   @f]
  * 
- *   @param  l  The order of the associated Legendre function.
+ *   @param  l  The degree of the associated Legendre function.
  *  @f$ l >= 0 @f$.
  *   @param  m  The order of the associated Legendre function.
  *  @f$ m <= l @f$.
  *   @param  x  The argument of the associated Legendre function.
  *  @f$ |x| <= 1 @f$.
+ *   @param  phase  The phase of the associated Legendre function.
+ *  Use -1 for the Condon-Shortley phase convention.
  */
 template
 _Tp
-__assoc_legendre_p(unsigned int __l, unsigned int __m, _Tp __x)
+__assoc_legendre_p(unsigned int __l, unsigned int __m, _Tp __x,
+  _Tp __phase = _Tp{+1})
 {
 
   if (__x < _Tp(-1) || __x > _Tp(+1))
@@ -160,7 +163,7 @@
   _Tp __fact = _Tp(1);
   for (unsigned int __i = 1; __i <= __m; ++__i)
 {
-  __p_mm *= -__fact * __root;
+  __p_mm *= __phase * __fact * __root;
   __fact += _Tp(2);
 }
 }
@@ -205,8 +208,10 @@
  *   but this factor is rather large for large @f$ l @f$ and @f$ m @f$
  *   and so this function is stable for larger differences of @f$ l @f$
  *   and @f$ m @f$.
+ *   @note Unlike the case for __assoc_legendre_p the Condon-Shortley
+ *   phase factor @f$ (-1)^m @f$ is present here.
  * 
- *   @param  l  The order of the spherical associated Legendre function.
+ *   @param  l  The degree of the spherical associated Legendre function.
  *  @f$ l >= 0 @f$.
  *   @param  m  The order of the spherical associated Legendre function.
  *  @f$ m <= l @f$.
@@ -265,19 +270,15 @@
   const _Tp __lnpre_val =
 -_Tp(0.25L) * __numeric_constants<_Tp>::__lnpi()
 + _Tp(0.5L) * (__lnpoch + __m * __lncirc);
-  _Tp __sr = std::sqrt((_Tp(2) + _Tp(1) / __m)
-   / (_Tp(4) * __numeric_constants<_Tp>::__pi()));
+  const _Tp __sr = std::sqrt((_Tp(2) + _Tp(1) / __m)
+ / (_Tp(4) * __numeric_constants<_Tp>::__pi()));
   _Tp __y_mm = __sgn * __sr * std::exp(__lnpre_val);
   _Tp __y_mp1m = __y_mp1m_factor * __y_mm;
 
   if (__l == __m)
-{
-  return __y_mm;
-}
+return __y_mm;
   else if (__l == __m + 1)
-{
-  return __y_mp1m;
-}
+return __y_mp1m;
   else
 {
   _Tp __y_lm = _Tp(0);
Index: testsuite/special_functions/02_assoc_legendre/check_value.cc
===
--- testsuite/special_functions/02_assoc_legendre/check_value.cc
(revision 259973)
+++ testsuite/special_functions/02_assoc_legendre/check_value.cc
(working copy)
@@ -1,6 +1,6 @@
 // { dg-do run { target c++11 } }
-// { 

Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-05-06 Thread Ed Smith-Rowland

Michele,

So I think the patch you had plus tests
testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc
plus I'd like the new tests also in
  testsuite/special_functions/08_cyl_bessel_j/check_value.cc
  testsuite/special_functions/10_cyl_neumann/check_value.cc
for C++17.

Put that up with a Changelog and see if we're all good.

Thank you for going through this and other math issues.

Ed



Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-05-05 Thread Ed Smith-Rowland

On 01/08/2018 02:08 PM, Michele Pezzutti wrote:

Formatting fixed.

diff --git a/libstdc++-v3/include/tr1/bessel_function.tcc 
b/libstdc++-v3/include/tr1/bessel_function.tcc

index 7ac733d..5f8fc9f 100644
--- a/libstdc++-v3/include/tr1/bessel_function.tcc
+++ b/libstdc++-v3/include/tr1/bessel_function.tcc
@@ -27,6 +27,10 @@
  *  Do not attempt to use it directly. @headername{tr1/cmath}
  */

+/* __cyl_bessel_jn_asymp adapted from GNU GSL version 2.4 
specfunc/bessel_j.c

+ * Copyright (C) 1996-2003 Gerard Jungman
+ */
+
 //
 // ISO C++ 14882 TR1: 5.2  Special functions
 //
@@ -358,16 +362,42 @@ namespace tr1
 void
 __cyl_bessel_jn_asymp(_Tp __nu, _Tp __x, _Tp & __Jnu, _Tp & __Nnu)
 {
-  const _Tp __mu   = _Tp(4) * __nu * __nu;
-  const _Tp __mum1 = __mu - _Tp(1);
-  const _Tp __mum9 = __mu - _Tp(9);
-  const _Tp __mum25 = __mu - _Tp(25);
-  const _Tp __mum49 = __mu - _Tp(49);
-  const _Tp __xx = _Tp(64) * __x * __x;
-  const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx)
-    * (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx));
-  const _Tp __Q = __mum1 / (_Tp(8) * __x)
-    * (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx));
+  const _Tp __mu = _Tp(4) * __nu * __nu;
+  const _Tp __8x = _Tp(8) * __x;
+
+  _Tp __P = _Tp(0);
+  _Tp __Q = _Tp(0);
+
+  _Tp __k = _Tp(0);
+  _Tp __term = _Tp(1);
+
+  int __epsP = 0;
+  int __epsQ = 0;
+
+  _Tp __eps = std::numeric_limits<_Tp>::epsilon();
+
+  do
+    {
+  __term *= (__k == 0
+ ? _Tp(1)
+ : -(__mu - (2 * __k - 1) * (2 * __k - 1)) / (__k 
* __8x));

+
+  __epsP = std::abs(__term) < std::abs(__eps * __P);
+  __P += __term;
+
+  __k++;
+
+  __term *= (__mu - (2 * __k - 1) * (2 * __k - 1)) / (__k * 
__8x);

+  __epsQ = std::abs(__term) < std::abs(__eps * __Q);
+  __Q += __term;
+
+  if (__epsP && __epsQ && __k > __nu / 2.)
+    break;
+
+  __k++;
+    }
+  while (__k < 1000);
+

   const _Tp __chi = __x - (__nu + _Tp(0.5L))
 * __numeric_constants<_Tp>::__pi_2();

On 01/06/2018 10:23 AM, Paolo Carlini wrote:

Hi,

On 05/01/2018 23:46, Michele Pezzutti wrote:
+ __term *= (__k == 0) ? _Tp(1) : -(__mu - (2 * __k - 1) * (2 * __k 
- 1))

+    / (__k * __8x);
In such cases, per the Coding Standards, you want an outer level of 
parentheses wrapping the whole right side expression. See toward the 
end of 
https://www.gnu.org/prep/standards/html_node/Formatting.html#Formatting. 
I see that many other places will need fixing, at some point - this 
rather straightforward rule is often overlooked leading to brittle 
formatting of many expressions, probably because it's really obvious 
in practice only together with Emacs, I'm not sure.


Also - this kind of stylistic nitpicking is partially personal taste 
- the parentheses around (__k == 0) seem definitely redundant to me, 
and I don't think you would find many examples of that in our code.


About the Assignement, please be patient. For example, used to be the 
case that when RMS was traveling couldn't process Assignments, for 
example. It can be slow for many reasons, it's 100% normal.


Paolo..






Hi all,

I'd like us to get this in.

Michele, how is the Copyright assignment going?

I'd like to push it down through brach/gcc-6 also.

Ed




Re: [PATCH] PR libstdc++/80506 fix constant used in condition

2018-05-05 Thread Ed Smith-Rowland

On 04/26/2017 05:16 AM, Jonathan Wakely wrote:

On 26/04/17 11:14 +0200, Paolo Carlini wrote:

.. or maybe using the wrong constant only impacts the performance?!?


Yes, I think so. I did some very simple sanity tests and the numbers
were identical before and after.




I was backporting this and saw that __generate_impl does this twice more.

For trunk and branch-8 I have these patches.

OK?



2018-05-07  Edward Smith-Rowland  <3dw...@verizon.net>

Moar PR libstdc++/80506
* include/bits/random.tcc (gamma_distribution::__generate_impl()):
Fix magic number used in loop condition.
Index: include/bits/random.tcc
===
--- include/bits/random.tcc (revision 259965)
+++ include/bits/random.tcc (working copy)
@@ -2408,7 +2408,7 @@
  __v = __v * __v * __v;
  __u = __aurng();
}
- while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n
+ while (__u > result_type(1.0) - 0.0331 * __n * __n * __n * __n
 && (std::log(__u) > (0.5 * __n * __n + __a1
  * (1.0 - __v + std::log(__v);
 
@@ -2429,7 +2429,7 @@
  __v = __v * __v * __v;
  __u = __aurng();
}
- while (__u > result_type(1.0) - 0.331 * __n * __n * __n * __n
+ while (__u > result_type(1.0) - 0.0331 * __n * __n * __n * __n
 && (std::log(__u) > (0.5 * __n * __n + __a1
  * (1.0 - __v + std::log(__v);
 


[libstdc++; pr66689; pr68397] Backport special function fixes to 7.

2018-04-26 Thread Ed Smith-Rowland
I'm thinking of going back on my choice not to fix special function bugs 
on 7.


These build and test clean on gcc-7.

OK?


2018-04-30  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/pr66689 - comp_ellint_3 and ellint_3 return garbage values
* include/tr1/ell_integral.tcc: Correct the nu sign convention
in ellint_3 and comp_ellint_3.
* testsuite/tr1/5_numerical_facilities/special_functions/
06_comp_ellint_3/check_value.cc: Regen with correct values.
* testsuite/tr1/5_numerical_facilities/special_functions/
14_ellint_3/check_value.cc: Ditto.
* testsuite/special_functions/06_comp_ellint_3/check_value.cc: Ditto.
* testsuite/special_functions/13_ellint_3/check_value.cc: Ditto.
* testsuite/special_functions/06_comp_ellint_3/pr66689.cc: New.
* testsuite/special_functions/13_ellint_3/pr66689.cc: New.
* testsuite/tr1/5_numerical_facilities/special_functions/
06_comp_ellint_3/pr66689.cc: New.
* testsuite/tr1/5_numerical_facilities/special_functions/
14_ellint_3/pr66689.cc: New.
Index: include/tr1/ell_integral.tcc
===
--- include/tr1/ell_integral.tcc(revision 259666)
+++ include/tr1/ell_integral.tcc(working copy)
@@ -685,8 +685,8 @@
   const _Tp __kk = __k * __k;
 
   return __ellint_rf(_Tp(0), _Tp(1) - __kk, _Tp(1))
-   - __nu
-   * __ellint_rj(_Tp(0), _Tp(1) - __kk, _Tp(1), _Tp(1) + __nu)
+   + __nu
+   * __ellint_rj(_Tp(0), _Tp(1) - __kk, _Tp(1), _Tp(1) - __nu)
/ _Tp(3);
 }
 }
@@ -735,9 +735,9 @@
 
   const _Tp __Pi = __s
  * __ellint_rf(__cc, _Tp(1) - __kk * __ss, _Tp(1))
- - __nu * __sss
+ + __nu * __sss
  * __ellint_rj(__cc, _Tp(1) - __kk * __ss, _Tp(1),
-   _Tp(1) + __nu * __ss) / _Tp(3);
+   _Tp(1) - __nu * __ss) / _Tp(3);
 
   if (__n == 0)
 return __Pi;
Index: testsuite/special_functions/06_comp_ellint_3/pr66689.cc
===
--- testsuite/special_functions/06_comp_ellint_3/pr66689.cc (nonexistent)
+++ testsuite/special_functions/06_comp_ellint_3/pr66689.cc (working copy)
@@ -0,0 +1,24 @@
+// { dg-do run { target c++11 } }
+// { dg-require-c-std "" }
+// { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
+// { dg-add-options ieee }
+
+#include 
+#include 
+
+void
+test01()
+{
+  double Pi1 = std::comp_ellint_3(0.75, 0.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::comp_ellint_3(0.75, 0.5);
+  VERIFY(std::abs(Pi2 - 2.80011) < 0.1);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
Index: testsuite/special_functions/13_ellint_3/pr66689.cc
===
--- testsuite/special_functions/13_ellint_3/pr66689.cc  (nonexistent)
+++ testsuite/special_functions/13_ellint_3/pr66689.cc  (working copy)
@@ -0,0 +1,26 @@
+// { dg-do run { target c++11 } }
+// { dg-require-c-std "" }
+// { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
+// { dg-add-options ieee }
+
+#include 
+#include 
+
+void
+test01()
+{
+  const double pi = 3.141592654;
+
+  double Pi1 = std::ellint_3(0.75, 0.0, pi / 2.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::ellint_3(0.75, 0.5, pi / 2.0);
+  VERIFY(std::abs(Pi2 - 2.80011) < 0.1);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
Index: 
testsuite/tr1/5_numerical_facilities/special_functions/06_comp_ellint_3/pr66689.cc
===
--- 
testsuite/tr1/5_numerical_facilities/special_functions/06_comp_ellint_3/pr66689.cc
  (nonexistent)
+++ 
testsuite/tr1/5_numerical_facilities/special_functions/06_comp_ellint_3/pr66689.cc
  (working copy)
@@ -0,0 +1,20 @@
+
+#include 
+#include 
+
+void
+test01()
+{
+  double Pi1 = std::tr1::comp_ellint_3(0.75, 0.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::tr1::comp_ellint_3(0.75, 0.5);
+  VERIFY(std::abs(Pi2 - 2.80011) < 0.1);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
Index: 
testsuite/tr1/5_numerical_facilities/special_functions/14_ellint_3/pr66689.cc
===
--- 
testsuite/tr1/5_numerical_facilities/special_functions/14_ellint_3/pr66689.cc   
(nonexistent)
+++ 
testsuite/tr1/5_numerical_facilities/special_functions/14_ellint_3/pr66689.cc   
(working copy)
@@ -0,0 +1,22 @@
+
+#include 
+#include 
+
+void
+test01()
+{
+  const double pi = 3.141592654;
+
+  double Pi1 = std::tr1::ellint_3(0.75, 0.0, pi / 2.0);
+  VERIFY(std::abs(Pi1 - 1.91099) < 0.1);
+
+  double Pi2 = std::tr1::ellint_3(0.75, 0.5, pi / 2.0);
+  VERIFY(std::abs(Pi2 

Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-01-05 Thread Ed Smith-Rowland

On 01/04/2018 03:54 PM, Michele Pezzutti wrote:



On 01/04/2018 06:16 PM, Ed Smith-Rowland wrote:

On 01/03/2018 02:49 PM, Michele Pezzutti wrote:


Hi.

On 01/02/2018 05:43 PM, Michele Pezzutti wrote:


On 01/02/2018 02:28 AM, Ed Smith-Rowland wrote:

I like the patch.

I have a similar one in the tr29124 branch.

Anyway, I got held up and I think it's good to have new folks 
looking into this.


It looks good except that you need to uglify k.


I looked at the GSL implementation, based on same reference, and 
their loop is cleaner. What about porting that implementation here? 
Possible?


My implementation is also using one more term for P than for Q, 
which is discouraged in GSL, according to their comments.


Ed, do you have any comment about this point?
Regarding the 2nd line, after my observations, usually term stops 
contributing to P, Q before k > nu/2, so actually, an offset by one 
is most likely without consequences.

GSL implementation is nevertheless more elegant.


I've seen their implementation.  It's tight.  Feel free to port it.
I assume this is it:
int
gsl_sf_bessel_Jnu_asympx_e(const double nu, const double x, 
gsl_sf_result * result);


You do want to give Q or b one more term so as to make that last 
factor as small as possible.  They're right.




Here it is.

diff --git a/libstdc++-v3/include/tr1/bessel_function.tcc 
b/libstdc++-v3/include/tr1/bessel_function.tcc

index 7ac733d..7842350 100644
--- a/libstdc++-v3/include/tr1/bessel_function.tcc
+++ b/libstdc++-v3/include/tr1/bessel_function.tcc
@@ -353,21 +353,47 @@ namespace tr1
  *   @param  __x   The argument of the Bessel functions.
  *   @param  __Jnu  The output Bessel function of the first kind.
  *   @param  __Nnu  The output Neumann function (Bessel function 
of the second kind).

+ *
+ *  Adapted for libstdc++ from GNU GSL version 2.4 
specfunc/bessel_j.c
+ *  Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003 Gerard 
Jungman

  */
 template 
 void
 __cyl_bessel_jn_asymp(_Tp __nu, _Tp __x, _Tp & __Jnu, _Tp & __Nnu)
 {
   const _Tp __mu   = _Tp(4) * __nu * __nu;
-  const _Tp __mum1 = __mu - _Tp(1);
-  const _Tp __mum9 = __mu - _Tp(9);
-  const _Tp __mum25 = __mu - _Tp(25);
-  const _Tp __mum49 = __mu - _Tp(49);
-  const _Tp __xx = _Tp(64) * __x * __x;
-  const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx)
-    * (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx));
-  const _Tp __Q = __mum1 / (_Tp(8) * __x)
-    * (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx));
+  const _Tp __8x = _Tp(8) * __x;
+
+  _Tp __P = _Tp(0);
+  _Tp __Q = _Tp(0);
+
+  _Tp k = _Tp(0);
+  _Tp __term = _Tp(1);
+
+  int __epsP = 0;
+  int __epsQ = 0;
+
+  _Tp __eps = std::numeric_limits<_Tp>::epsilon();
+
+  do
+    {
+  __term *= (k == 0) ? _Tp(1) : -(__mu - (2 * k - 1) * (2 * k 
- 1)) / (k * __8x);

+  __epsP = std::abs(__term) < std::abs(__eps * __P);
+  __P += __term;
+
+  k++;
+
+  __term *= (__mu - (2 * k - 1) * (2 * k - 1)) / (k * __8x);
+  __epsQ = std::abs(__term) < std::abs(__eps * __Q);
+  __Q += __term;
+
+  if (__epsP && __epsQ && k > __nu / 2.)
+    break;
+
+  k++;
+    }
+  while (k < 1000);
+

   const _Tp __chi = __x - (__nu + _Tp(0.5L))
 * __numeric_constants<_Tp>::__pi_2();



In principal, these ideas should be ported to I,K but I think (and 
IIRC GSL agrees) these under,over-flow before they have much effect.
I think I put the full series in there.  They could use a similar 
clean-up.


But let's get this in there first.

Ed





This looks good to me.  The only nit is that you have to uglify the k 
loop variable.


(I hope we can un-uglify our variables when modules come!)

Do you have copyright assignment in place and all that?

Ed





Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-01-04 Thread Ed Smith-Rowland

On 01/03/2018 02:49 PM, Michele Pezzutti wrote:


Hi.

On 01/02/2018 05:43 PM, Michele Pezzutti wrote:


On 01/02/2018 02:28 AM, Ed Smith-Rowland wrote:

I like the patch.

I have a similar one in the tr29124 branch.

Anyway, I got held up and I think it's good to have new folks 
looking into this.


It looks good except that you need to uglify k.


I looked at the GSL implementation, based on same reference, and 
their loop is cleaner. What about porting that implementation here? 
Possible?


My implementation is also using one more term for P than for Q, which 
is discouraged in GSL, according to their comments.


Ed, do you have any comment about this point?
Regarding the 2nd line, after my observations, usually term stops 
contributing to P, Q before k > nu/2, so actually, an offset by one is 
most likely without consequences.

GSL implementation is nevertheless more elegant.


I've seen their implementation.  It's tight.  Feel free to port it.
I assume this is it:
int
gsl_sf_bessel_Jnu_asympx_e(const double nu, const double x, 
gsl_sf_result * result);


You do want to give Q or b one more term so as to make that last factor 
as small as possible.  They're right.


In principal, these ideas should be ported to I,K but I think (and IIRC 
GSL agrees) these under,over-flow before they have much effect.

I think I put the full series in there.  They could use a similar clean-up.

But let's get this in there first.

Ed




Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-01-02 Thread Ed Smith-Rowland

On 01/02/2018 04:41 PM, Michele Pezzutti wrote:

On 01/02/2018 05:59 PM, Ed Smith-Rowland wrote:

OK,

on *third* look summing up to k = nu/2 at minimum will a achieve the 
result of not blowing up the asymptotic series:


nu^2 - (2k-1)^2.  And it will do that without a check.

This stopping criterion should work even near x=nu which would be the 
most difficult case.  The sum could go further for larger x but let's 
just go with your termination criterion for now. Later, with some 
experimentation, we could sum up to nu/2 at a minimum *then* snoop 
forward until the terms start drifting up. Or we could just solve 
k_max for this case as a function of x. Also, we may never need these 
extras.
For what I could see, 'term' stops to contributing to P, Q few steps 
before k = nu /2.



Right.  I can see these terms rising, sometimes quite high, then falling.
In many experiments, the sums converge before the terms blow up.

In my old impl, I gave up too easily.
Perhaps, in general, one could wait until the terms started decreasing, 
*then* if subsequent terms start growing again exit loop.

But it seems I never get to that point before sum convergence.

On the good side it seems that if x >= 20 nu then you can go quite high 
in nu.


nu =    1000
x  =   2
Jnu  = 0.00540683536187055
Nnu  =    -0.00162387432151849
Jnua = 0.00540683536187055
Nnua =    -0.00162387432151849
Jnua - Jnu =   0
Nnua - Nnu =   0
Jpnu  = 0.00162170521572447
Npnu  =  0.0054001182451475
Jpnua = 0.00162170521572447
Npnua =  0.0054001182451475
Jpnua - Jpnu =   0
Npnua - Npnu =   0
pi x Wronski / 2 =    1.0022382762



Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-01-02 Thread Ed Smith-Rowland

On 12/31/2017 09:38 PM, Michele Pezzutti wrote:

Hi.

This patch intends to fix Bug 83566 - cyl_bessel_j returns wrong 
result for x>1000 for high orders.
Seehttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=83566 forissue 
description.


    * libstdc++-v3/include/tr1/bessel_function.tcc
  Series expansion in __cyl_bessel_jn_asymp() shall not be 
truncated at the first terms.
  At least nu/2 terms shall be added, in order to have a 
guaranteed error bound.


    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

  Testcase for x > 1000 added.

    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

Testcase for x > 1000 added.


diff --git a/libstdc++-v3/include/tr1/bessel_function.tcc 
b/libstdc++-v3/include/tr1/bessel_function.tcc

index 7ac733d..852a31e 100644
--- a/libstdc++-v3/include/tr1/bessel_function.tcc
+++ b/libstdc++-v3/include/tr1/bessel_function.tcc
@@ -359,15 +359,32 @@ namespace tr1
 __cyl_bessel_jn_asymp(_Tp __nu, _Tp __x, _Tp & __Jnu, _Tp & __Nnu)
 {
   const _Tp __mu   = _Tp(4) * __nu * __nu;
-  const _Tp __mum1 = __mu - _Tp(1);
-  const _Tp __mum9 = __mu - _Tp(9);
-  const _Tp __mum25 = __mu - _Tp(25);
-  const _Tp __mum49 = __mu - _Tp(49);
-  const _Tp __xx = _Tp(64) * __x * __x;
-  const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx)
-    * (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx));
-  const _Tp __Q = __mum1 / (_Tp(8) * __x)
-    * (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx));
+  const _Tp __8x = _Tp(8) * __x;
+
+  _Tp __P = _Tp(1);
+  _Tp __Q = _Tp(0);
+
+  _Tp __eps = std::numeric_limits<_Tp>::epsilon();
+
+  _Tp __term = _Tp(1);
+  _Tp __epsP = _Tp(0);
+  _Tp __epsQ = _Tp(0);
+
+  unsigned long __2k;
+  for (unsigned long k = 1; k < 1000; k+=2) {
+  __2k = 2 * k;
+
+  __term *= (__mu - _Tp((__2k - 1) * (__2k - 1))) / (k * __8x);
+  __Q += __term;
+  __epsQ = std::abs(__term) < std::abs(__eps * __Q);
+
+  __term *= -(__mu - _Tp((__2k + 1) * (__2k + 1)))/ (_Tp(k + 
1) * __8x);

+  __P += __term;
+  __epsP = std::abs(__term) < std::abs(__eps * __P);
+
+  if (__epsP && __epsQ && k > __nu / 2.)
+    break;
+  }

   const _Tp __chi = __x - (__nu + _Tp(0.5L))
 * __numeric_constants<_Tp>::__pi_2();


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc 


index 26f4dd3..e340b78 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

@@ -698,6 +698,26 @@ data026[21] =
 };
 const double toler026 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 2.5857788132910287e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11
+const testcase_cyl_bessel_j
+data027[11] =
+{
+  { 0.0116761350077845, 100., 1000. },
+  {-0.0116998547780258, 100., 1100. },
+  {-0.0228014834050837, 100., 1200. },
+  {-0.0169735007873739, 100., 1300. },
+  {-0.0014154528803530, 100., 1400. },
+  { 0.017265844988, 100., 1500. },
+  { 0.0198025620201474, 100., 1600. },
+  { 0.0161297712798388, 100., 1700. },
+  { 0.0053753369281577, 100., 1800. },
+  {-0.0069238868725646, 100., 1900. },
+  {-0.0154878717200738, 100., 2000. },
+};
+const double toler027 = 1.0006e-10;
+
 template
   void
   test(const testcase_cyl_bessel_j ()[Num], Ret toler)
@@ -748,5 +768,6 @@ main()
   test(data024, toler024);
   test(data025, toler025);
   test(data026, toler026);
+  test(data027, toler027);
   return 0;
 }


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc 


index 5579149..9caf836 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

@@ -742,6 +742,26 @@ data028[20] =
 };
 const double toler028 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 3.1049815496508870e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11

Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-01-01 Thread Ed Smith-Rowland

On 12/31/2017 09:38 PM, Michele Pezzutti wrote:

Hi.

This patch intends to fix Bug 83566 - cyl_bessel_j returns wrong 
result for x>1000 for high orders.
Seehttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=83566 forissue 
description.


    * libstdc++-v3/include/tr1/bessel_function.tcc
  Series expansion in __cyl_bessel_jn_asymp() shall not be 
truncated at the first terms.
  At least nu/2 terms shall be added, in order to have a 
guaranteed error bound.


    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

  Testcase for x > 1000 added.

    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

Testcase for x > 1000 added.


diff --git a/libstdc++-v3/include/tr1/bessel_function.tcc 
b/libstdc++-v3/include/tr1/bessel_function.tcc

index 7ac733d..852a31e 100644
--- a/libstdc++-v3/include/tr1/bessel_function.tcc
+++ b/libstdc++-v3/include/tr1/bessel_function.tcc
@@ -359,15 +359,32 @@ namespace tr1
 __cyl_bessel_jn_asymp(_Tp __nu, _Tp __x, _Tp & __Jnu, _Tp & __Nnu)
 {
   const _Tp __mu   = _Tp(4) * __nu * __nu;
-  const _Tp __mum1 = __mu - _Tp(1);
-  const _Tp __mum9 = __mu - _Tp(9);
-  const _Tp __mum25 = __mu - _Tp(25);
-  const _Tp __mum49 = __mu - _Tp(49);
-  const _Tp __xx = _Tp(64) * __x * __x;
-  const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx)
-    * (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx));
-  const _Tp __Q = __mum1 / (_Tp(8) * __x)
-    * (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx));
+  const _Tp __8x = _Tp(8) * __x;
+
+  _Tp __P = _Tp(1);
+  _Tp __Q = _Tp(0);
+
+  _Tp __eps = std::numeric_limits<_Tp>::epsilon();
+
+  _Tp __term = _Tp(1);
+  _Tp __epsP = _Tp(0);
+  _Tp __epsQ = _Tp(0);
+
+  unsigned long __2k;
+  for (unsigned long k = 1; k < 1000; k+=2) {
+  __2k = 2 * k;
+
+  __term *= (__mu - _Tp((__2k - 1) * (__2k - 1))) / (k * __8x);
+  __Q += __term;
+  __epsQ = std::abs(__term) < std::abs(__eps * __Q);
+
+  __term *= -(__mu - _Tp((__2k + 1) * (__2k + 1)))/ (_Tp(k + 
1) * __8x);

+  __P += __term;
+  __epsP = std::abs(__term) < std::abs(__eps * __P);
+
+  if (__epsP && __epsQ && k > __nu / 2.)
+    break;
+  }

   const _Tp __chi = __x - (__nu + _Tp(0.5L))
 * __numeric_constants<_Tp>::__pi_2();


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc 


index 26f4dd3..e340b78 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

@@ -698,6 +698,26 @@ data026[21] =
 };
 const double toler026 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 2.5857788132910287e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11
+const testcase_cyl_bessel_j
+data027[11] =
+{
+  { 0.0116761350077845, 100., 1000. },
+  {-0.0116998547780258, 100., 1100. },
+  {-0.0228014834050837, 100., 1200. },
+  {-0.0169735007873739, 100., 1300. },
+  {-0.0014154528803530, 100., 1400. },
+  { 0.017265844988, 100., 1500. },
+  { 0.0198025620201474, 100., 1600. },
+  { 0.0161297712798388, 100., 1700. },
+  { 0.0053753369281577, 100., 1800. },
+  {-0.0069238868725646, 100., 1900. },
+  {-0.0154878717200738, 100., 2000. },
+};
+const double toler027 = 1.0006e-10;
+
 template
   void
   test(const testcase_cyl_bessel_j ()[Num], Ret toler)
@@ -748,5 +768,6 @@ main()
   test(data024, toler024);
   test(data025, toler025);
   test(data026, toler026);
+  test(data027, toler027);
   return 0;
 }


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc 


index 5579149..9caf836 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

@@ -742,6 +742,26 @@ data028[20] =
 };
 const double toler028 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 3.1049815496508870e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11

Re: Fix Bug 83566 - cyl_bessel_j returns wrong result for x>1000 for high orders

2018-01-01 Thread Ed Smith-Rowland

On 12/31/2017 09:38 PM, Michele Pezzutti wrote:

Hi.

This patch intends to fix Bug 83566 - cyl_bessel_j returns wrong 
result for x>1000 for high orders.
Seehttps://gcc.gnu.org/bugzilla/show_bug.cgi?id=83566 forissue 
description.


    * libstdc++-v3/include/tr1/bessel_function.tcc
  Series expansion in __cyl_bessel_jn_asymp() shall not be 
truncated at the first terms.
  At least nu/2 terms shall be added, in order to have a 
guaranteed error bound.


    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

  Testcase for x > 1000 added.

    * 
libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

Testcase for x > 1000 added.


diff --git a/libstdc++-v3/include/tr1/bessel_function.tcc 
b/libstdc++-v3/include/tr1/bessel_function.tcc

index 7ac733d..852a31e 100644
--- a/libstdc++-v3/include/tr1/bessel_function.tcc
+++ b/libstdc++-v3/include/tr1/bessel_function.tcc
@@ -359,15 +359,32 @@ namespace tr1
 __cyl_bessel_jn_asymp(_Tp __nu, _Tp __x, _Tp & __Jnu, _Tp & __Nnu)
 {
   const _Tp __mu   = _Tp(4) * __nu * __nu;
-  const _Tp __mum1 = __mu - _Tp(1);
-  const _Tp __mum9 = __mu - _Tp(9);
-  const _Tp __mum25 = __mu - _Tp(25);
-  const _Tp __mum49 = __mu - _Tp(49);
-  const _Tp __xx = _Tp(64) * __x * __x;
-  const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx)
-    * (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx));
-  const _Tp __Q = __mum1 / (_Tp(8) * __x)
-    * (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx));
+  const _Tp __8x = _Tp(8) * __x;
+
+  _Tp __P = _Tp(1);
+  _Tp __Q = _Tp(0);
+
+  _Tp __eps = std::numeric_limits<_Tp>::epsilon();
+
+  _Tp __term = _Tp(1);
+  _Tp __epsP = _Tp(0);
+  _Tp __epsQ = _Tp(0);
+
+  unsigned long __2k;
+  for (unsigned long k = 1; k < 1000; k+=2) {
+  __2k = 2 * k;
+
+  __term *= (__mu - _Tp((__2k - 1) * (__2k - 1))) / (k * __8x);
+  __Q += __term;
+  __epsQ = std::abs(__term) < std::abs(__eps * __Q);
+
+  __term *= -(__mu - _Tp((__2k + 1) * (__2k + 1)))/ (_Tp(k + 
1) * __8x);

+  __P += __term;
+  __epsP = std::abs(__term) < std::abs(__eps * __P);
+
+  if (__epsP && __epsQ && k > __nu / 2.)
+    break;
+  }

   const _Tp __chi = __x - (__nu + _Tp(0.5L))
 * __numeric_constants<_Tp>::__pi_2();


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc 


index 26f4dd3..e340b78 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/09_cyl_bessel_j/check_value.cc

@@ -698,6 +698,26 @@ data026[21] =
 };
 const double toler026 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 2.5857788132910287e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11
+const testcase_cyl_bessel_j
+data027[11] =
+{
+  { 0.0116761350077845, 100., 1000. },
+  {-0.0116998547780258, 100., 1100. },
+  {-0.0228014834050837, 100., 1200. },
+  {-0.0169735007873739, 100., 1300. },
+  {-0.0014154528803530, 100., 1400. },
+  { 0.017265844988, 100., 1500. },
+  { 0.0198025620201474, 100., 1600. },
+  { 0.0161297712798388, 100., 1700. },
+  { 0.0053753369281577, 100., 1800. },
+  {-0.0069238868725646, 100., 1900. },
+  {-0.0154878717200738, 100., 2000. },
+};
+const double toler027 = 1.0006e-10;
+
 template
   void
   test(const testcase_cyl_bessel_j ()[Num], Ret toler)
@@ -748,5 +768,6 @@ main()
   test(data024, toler024);
   test(data025, toler025);
   test(data026, toler026);
+  test(data027, toler027);
   return 0;
 }


diff --git 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc 


index 5579149..9caf836 100644
--- 
a/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc
+++ 
b/libstdc++-v3/testsuite/tr1/5_numerical_facilities/special_functions/11_cyl_neumann/check_value.cc

@@ -742,6 +742,26 @@ data028[20] =
 };
 const double toler028 = 1.0006e-11;

+// Test data for nu=100.00.
+// max(|f - f_GSL|): 3.1049815496508870e-14
+// max(|f - f_GSL| / |f_GSL|): 1.6767662425535933e-11

Re: [libstdc++] Expose Airy functions.

2017-11-18 Thread Ed Smith-Rowland

Here is the final patch fir libstdc++ Airy functions...

2017-11-18  Edward Smith-Rowland  <3dw...@verizon.net>

* include/bits/specfun.h: Expose airy_ai and airy_bi.
* include/tr1/modified_bessel_func.tcc: Treat NaN and inf arg, return.
* testsuite/ext/special_functions/airy_ai/check_nan.cc: New.
* testsuite/ext/special_functions/airy_ai/check_value.cc: New.
* testsuite/ext/special_functions/airy_ai/compile.cc: New.
* testsuite/ext/special_functions/airy_bi/check_nan.cc: New.
* testsuite/ext/special_functions/airy_bi/check_value.cc: New.
* testsuite/ext/special_functions/airy_bi/compile.cc: New.
Index: include/bits/specfun.h
===
--- include/bits/specfun.h	(revision 254915)
+++ include/bits/specfun.h	(working copy)
@@ -1206,6 +1206,78 @@
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+  // Airy functions
+
+  /**
+   * Return the Airy function @f$ Ai(x) @f$ of @c float argument x.
+   */
+  inline float
+  airy_aif(float __x)
+  {
+float __Ai, __Bi, __Aip, __Bip;
+std::__detail::__airy(__x, __Ai, __Bi, __Aip, __Bip);
+return __Ai;
+  }
+
+  /**
+   * Return the Airy function @f$ Ai(x) @f$ of long double argument x.
+   */
+  inline long double
+  airy_ail(long double __x)
+  {
+long double __Ai, __Bi, __Aip, __Bip;
+std::__detail::__airy(__x, __Ai, __Bi, __Aip, __Bip);
+return __Ai;
+  }
+
+  /**
+   * Return the Airy function @f$ Ai(x) @f$ of real argument x.
+   */
+  template
+inline typename __gnu_cxx::__promote<_Tp>::__type
+airy_ai(_Tp __x)
+{
+  typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
+  __type __Ai, __Bi, __Aip, __Bip;
+  std::__detail::__airy<__type>(__x, __Ai, __Bi, __Aip, __Bip);
+  return __Ai;
+}
+
+  /**
+   * Return the Airy function @f$ Bi(x) @f$ of @c float argument x.
+   */
+  inline float
+  airy_bif(float __x)
+  {
+float __Ai, __Bi, __Aip, __Bip;
+std::__detail::__airy(__x, __Ai, __Bi, __Aip, __Bip);
+return __Bi;
+  }
+
+  /**
+   * Return the Airy function @f$ Bi(x) @f$ of long double argument x.
+   */
+  inline long double
+  airy_bil(long double __x)
+  {
+long double __Ai, __Bi, __Aip, __Bip;
+std::__detail::__airy(__x, __Ai, __Bi, __Aip, __Bip);
+return __Bi;
+  }
+
+  /**
+   * Return the Airy function @f$ Bi(x) @f$ of real argument x.
+   */
+  template
+inline typename __gnu_cxx::__promote<_Tp>::__type
+airy_bi(_Tp __x)
+{
+  typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
+  __type __Ai, __Bi, __Aip, __Bip;
+  std::__detail::__airy<__type>(__x, __Ai, __Bi, __Aip, __Bip);
+  return __Bi;
+}
+
   // Confluent hypergeometric functions
 
   /**
Index: include/tr1/modified_bessel_func.tcc
===
--- include/tr1/modified_bessel_func.tcc	(revision 254915)
+++ include/tr1/modified_bessel_func.tcc	(working copy)
@@ -377,9 +377,20 @@
   const _Tp __absx = std::abs(__x);
   const _Tp __rootx = std::sqrt(__absx);
   const _Tp __z = _Tp(2) * __absx * __rootx / _Tp(3);
+  const _Tp _S_NaN = std::numeric_limits<_Tp>::quiet_NaN();
+  const _Tp _S_inf = std::numeric_limits<_Tp>::infinity();
 
-  if (__x > _Tp(0))
+  if (__isnan(__x))
+__Bip = __Aip = __Bi = __Ai = std::numeric_limits<_Tp>::quiet_NaN();
+  else if (__z == _S_inf)
 {
+	  __Aip = __Ai = _Tp{0};
+	  __Bip = __Bi = _S_inf;
+	}
+  else if (__z == -_S_inf)
+	__Bip = __Aip = __Bi = __Ai = _Tp{0};
+  else if (__x > _Tp(0))
+{
   _Tp __I_nu, __Ip_nu, __K_nu, __Kp_nu;
 
   __bessel_ik(_Tp(1) / _Tp(3), __z, __I_nu, __K_nu, __Ip_nu, __Kp_nu);
Index: include/tr1/modified_bessel_func.tcc
===
--- include/tr1/modified_bessel_func.tcc	(revision 254915)
+++ include/tr1/modified_bessel_func.tcc	(working copy)
@@ -377,9 +377,20 @@
   const _Tp __absx = std::abs(__x);
   const _Tp __rootx = std::sqrt(__absx);
   const _Tp __z = _Tp(2) * __absx * __rootx / _Tp(3);
+  const _Tp _S_NaN = std::numeric_limits<_Tp>::quiet_NaN();
+  const _Tp _S_inf = std::numeric_limits<_Tp>::infinity();
 
-  if (__x > _Tp(0))
+  if (__isnan(__x))
+__Bip = __Aip = __Bi = __Ai = std::numeric_limits<_Tp>::quiet_NaN();
+  else if (__z == _S_inf)
 {
+	  __Aip = __Ai = _Tp{0};
+	  __Bip = __Bi = _S_inf;
+	}
+  else if (__z == -_S_inf)
+	__Bip = __Aip = __Bi = __Ai = _Tp{0};
+  else if (__x > _Tp(0))
+{
   _Tp __I_nu, __Ip_nu, __K_nu, __Kp_nu;
 
   __bessel_ik(_Tp(1) / _Tp(3), __z, __I_nu, __K_nu, __Ip_nu, __Kp_nu);
Index: testsuite/ext/special_functions/airy_ai/check_nan.cc
===
--- testsuite/ext/special_functions/airy_ai/check_nan.cc	(nonexistent)
+++ 

Re: [PATCH libstdc++/66689] comp_ellint_3 and ellint_3 return garbage values

2017-11-18 Thread Ed Smith-Rowland

On 11/17/2017 03:54 PM, Jonathan Wakely wrote:


Hmm, you're probably right. I'd be tempted to though.

I had an idea.  What about a macro _GLIBCXX_ELLINT_3_POS_NU or something 
that:


1. would allow users to detect which convention is on by default.

2. They could set or unset to get the other convention.

It's bloody but it would work.  it would prevent users from having to 
test the compiler version and guess or check the value every time.


I feel that distros are likely to pick up gcc-7 soon and I'd like to do 
*something*.  This would be something of a transition path.


Ed




[PATCH libquadmath, pr68686] tgammaq(x) is always negative for noninteger x < 0

2017-11-13 Thread Ed Smith-Rowland

Here is a patch for tammaq for negative argument pr68686.

I know about depending on ports from upstream but this was done recently 
and this (tgammaq) was left out.


This patch is basically a one-liner.

I have test cases but libquadmath doesn't have a testsuite.

One test just shows alternating signs for -0.5Q, -1.5Q, -2.5Q, etc.

Another test verifies the Gamma reflection formula:

 tgamma(1-x) * tgamma(x) - pi / sinq(pi*x) is tiny.

Builds on x86_64-linux and tests correctly offline.


OK?


2017-11-10  Edward Smith-Rowland  <3dw...@verizon.net>

PR libquadmath/68686
* math/tgammaq.c: Correct sign for negative argument.
diff --git a/libquadmath/math/tgammaq.c b/libquadmath/math/tgammaq.c
index a07d583..3080094 100644
--- a/libquadmath/math/tgammaq.c
+++ b/libquadmath/math/tgammaq.c
@@ -47,7 +47,9 @@ tgammaq (__float128 x)
 /* x == -Inf.  According to ISO this is NaN.  */
 return x - x;
 
-  /* XXX FIXME.  */
   res = expq (lgammaq (x));
-  return signbitq (x) ? -res : res;
+  if (x > 0.0Q || ((int)(-x) & 1) == 1)
+return res;
+  else
+return -res;
 }
#include 
#include 

void
test_alt_signs()
{
  __float128 result = tgammaq(-1.5Q);
  assert(result > 0.0Q);

  result = tgammaq(-2.5Q);
  assert(result < 0.0Q);

  result = tgammaq(-3.5Q);
  assert(result > 0.0Q);

  result = tgammaq(-4.5Q);
  assert(result < 0.0Q);
}

/*
 * Return |\Gamma(x) \Gamma(1 - x) - \frac{\pi}{sin(\pi x)}|
 */
__float128
abs_delta(__float128 x)
{
  return fabsq(tgammaq(x) * tgammaq(1.0Q - x) - M_PIq / sinq(M_PIq * x));
}

/*
 * Test reflection: \Gamma(x) \Gamma(1 - x) = \frac{\pi}{sin(\pi x)}
 */
void
test_reflection()
{
  assert(abs_delta(+1.5Q) < 100 * FLT128_EPSILON);
  assert(abs_delta(+0.5Q) < 100 * FLT128_EPSILON);
  assert(abs_delta(-0.5Q) < 100 * FLT128_EPSILON);
  assert(abs_delta(-1.5Q) < 100 * FLT128_EPSILON);
  assert(abs_delta(-2.5Q) < 100 * FLT128_EPSILON);
}

int
main()
{
  test_alt_signs();

  test_reflection();

  return 0;
}


[PATCH, libstdc++] PR libstdc++/68397 std::tr1::expint fails ... long double arguments.

2017-04-20 Thread Ed Smith-Rowland

Here is a patch for

  PR libstdc++/68397 std::tr1::expint fails in __expint_En_cont_frac 
for some long double arguments due to low __max_iter value.


The proposed resolution of increasing the max_iter to 1000 is a simple 
and obvious fix.


Built and tested on x86_64-linux.

OK?

Ed


2017-04-20  Edward Smith-Rowland  <3dw...@verizon.net>

PR libstdc++/68397 std::tr1::expint fails ... long double arguments.
* include/tr1/exp_integral.tcc: Increase iteration limits.
* testsuite/tr1/5_numerical_facilities/special_functions/15_expint/
pr68397.cc: New test.
* testsuite/special_functions/14_expint/pr68397.cc: New test.
Index: include/tr1/exp_integral.tcc
===
--- include/tr1/exp_integral.tcc(revision 246797)
+++ include/tr1/exp_integral.tcc(working copy)
@@ -86,7 +86,7 @@
   _Tp __term = _Tp(1);
   _Tp __esum = _Tp(0);
   _Tp __osum = _Tp(0);
-  const unsigned int __max_iter = 100;
+  const unsigned int __max_iter = 1000;
   for (unsigned int __i = 1; __i < __max_iter; ++__i)
 {
   __term *= - __x / __i;
@@ -156,7 +156,7 @@
 _Tp
 __expint_En_series(unsigned int __n, _Tp __x)
 {
-  const unsigned int __max_iter = 100;
+  const unsigned int __max_iter = 1000;
   const _Tp __eps = std::numeric_limits<_Tp>::epsilon();
   const int __nm1 = __n - 1;
   _Tp __ans = (__nm1 != 0
@@ -202,7 +202,7 @@
 _Tp
 __expint_En_cont_frac(unsigned int __n, _Tp __x)
 {
-  const unsigned int __max_iter = 100;
+  const unsigned int __max_iter = 1000;
   const _Tp __eps = std::numeric_limits<_Tp>::epsilon();
   const _Tp __fp_min = std::numeric_limits<_Tp>::min();
   const int __nm1 = __n - 1;
Index: 
testsuite/tr1/5_numerical_facilities/special_functions/15_expint/pr68397.cc
===
--- testsuite/tr1/5_numerical_facilities/special_functions/15_expint/pr68397.cc 
(nonexistent)
+++ testsuite/tr1/5_numerical_facilities/special_functions/15_expint/pr68397.cc 
(working copy)
@@ -0,0 +1,46 @@
+// Copyright (C) 2017 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
+// .
+
+// PR libstdc++/68397 -  std::tr1::expint fails in __expint_En_cont_frac
+// for some long double arguments due to low __max_iter value
+
+#include 
+#include 
+
+void
+test01()
+{
+  // Answers from Wolfram Alpha.
+  long double ans_ok = -0.10001943365331651406888645149537315243646135979573L;
+  long double ans_bomb = 
-0.1027809650077516264612749163100483995270163783L;
+
+  long double Ei_ok = std::tr1::expint(-1.51L);
+  long double diff_ok = std::abs(Ei_ok - ans_ok);
+  VERIFY(diff_ok < 1.0e-15L);
+
+  long double Ei_bomb = std::tr1::expint(-1.450001L);
+  long double diff_bomb = std::abs(Ei_bomb - ans_bomb);
+  VERIFY(diff_bomb < 1.0e-15L);
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
+
Index: testsuite/special_functions/14_expint/pr68397.cc
===
--- testsuite/special_functions/14_expint/pr68397.cc(nonexistent)
+++ testsuite/special_functions/14_expint/pr68397.cc(working copy)
@@ -0,0 +1,47 @@
+// { dg-do run { target c++11 } }
+// { dg-options "-D__STDCPP_WANT_MATH_SPEC_FUNCS__" }
+// Copyright (C) 2017 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
+// .
+
+// PR libstdc++/68397 -  std::tr1::expint fails in __expint_En_cont_frac
+// for some long double arguments due to low __max_iter value
+
+#include 
+#include 
+
+int

Re: Add uniform_inside_sphere_distribution

2016-10-26 Thread Ed Smith-Rowland

On 10/26/2016 05:01 AM, Jonathan Wakely wrote:

On 25/10/16 08:20 -0400, Ed Smith-Rowland wrote:

+explicit
+param_type(_RealType __radius = _RealType(1))
+: _M_radius(__radius)
+{
+  _GLIBCXX_DEBUG_ASSERT(_M_radius > _RealType(0));


Nowadays we're able to do cheaper assertions when _GLIBCXX_ASSERTIONS
is defined, without the full debug mode (i.e. _GLIBCXX_DEBUG).

The macro above is only active for the full debug mode, but it looks
like a cheap check, should it use __glibcxx_assert instead?

It looks like we're not consistent about which one to use in
, which is probably my fault. Expensive checks like using
std::distance on forward iterators should use _GLIBCXX_DEBUG_ASSERT
but some of them look like they could use __glibcxx_assert.


This parameter check could definitely use __glibcxx_assert.

In fact, these two features look like 2/3 of the contracts proposal for 
C++ almost.  Or at least they could help.


Index: 
testsuite/ext/random/uniform_inside_sphere_distribution/cons/default.cc

===
--- 
testsuite/ext/random/uniform_inside_sphere_distribution/cons/default.cc 
(nonexistent)
+++ 
testsuite/ext/random/uniform_inside_sphere_distribution/cons/default.cc 
(working copy)

@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++11" }


In all the new tests please replace this dg-options directive with:

 { dg-do run { target cxx11 } }

so it can be tested for C++14 and C++17 too.

Done.

+// { dg-require-cstdint "" }
+//
+// Copyright (C) 2014 Free Software Foundation, Inc.


And update the dates to 2014-2016. 

Done.

Committed as 241562 with the attached .


Index: include/ext/random
===
--- include/ext/random  (revision 241499)
+++ include/ext/random  (working copy)
@@ -3493,6 +3493,218 @@
   _RealType>& __d2)
 { return !(__d1 == __d2); }
 
+
+  /**
+   * @brief A distribution for random coordinates inside a unit sphere.
+   */
+  template
+class uniform_inside_sphere_distribution
+{
+  static_assert(std::is_floating_point<_RealType>::value,
+   "template argument not a floating point type");
+  static_assert(_Dimen != 0, "dimension is zero");
+
+public:
+  /** The type of the range of the distribution. */
+  using result_type = std::array<_RealType, _Dimen>;
+
+  /** Parameter type. */
+  struct param_type
+  {
+   using distribution_type
+ = uniform_inside_sphere_distribution<_Dimen, _RealType>;
+   friend class uniform_inside_sphere_distribution<_Dimen, _RealType>;
+
+   explicit
+   param_type(_RealType __radius = _RealType(1))
+   : _M_radius(__radius)
+   {
+ __glibcxx_assert(_M_radius > _RealType(0));
+   }
+
+   _RealType
+   radius() const
+   { return _M_radius; }
+
+   friend bool
+   operator==(const param_type& __p1, const param_type& __p2)
+   { return __p1._M_radius == __p2._M_radius; }
+
+  private:
+   _RealType _M_radius;
+  };
+
+  /**
+   * @brief Constructors.
+   */
+  explicit
+  uniform_inside_sphere_distribution(_RealType __radius = _RealType(1))
+  : _M_param(__radius), _M_uosd()
+  { }
+
+  explicit
+  uniform_inside_sphere_distribution(const param_type& __p)
+  : _M_param(__p), _M_uosd()
+  { }
+
+  /**
+   * @brief Resets the distribution state.
+   */
+  void
+  reset()
+  { _M_uosd.reset(); }
+
+  /**
+   * @brief Returns the @f$radius@f$ of the distribution.
+   */
+  _RealType
+  radius() const
+  { return _M_param.radius(); }
+
+  /**
+   * @brief Returns the parameter set of the distribution.
+   */
+  param_type
+  param() const
+  { return _M_param; }
+
+  /**
+   * @brief Sets the parameter set of the distribution.
+   * @param __param The new parameter set of the distribution.
+   */
+  void
+  param(const param_type& __param)
+  { _M_param = __param; }
+
+  /**
+   * @brief Returns the greatest lower bound value of the distribution.
+   * This function makes no sense for this distribution.
+   */
+  result_type
+  min() const
+  {
+   result_type __res;
+   __res.fill(0);
+   return __res;
+  }
+
+  /**
+   * @brief Returns the least upper bound value of the distribution.
+   * This function makes no sense for this distribution.
+   */
+  result_type
+  max() const
+  {
+   result_type __res;
+   __res.fill(0);
+   return __res;
+  }
+
+  /**
+   * @brief Generating functions.
+   */
+  template
+   result_type
+   operator()(_UniformRandomNumberGenerator& __urng)
+   { return this->operator()(__urng, _M_para

Re: Add uniform_inside_sphere_distribution

2016-10-25 Thread Ed Smith-Rowland

All,

Here is the library extension for uniform_inside _sphere_distribution.
It works from discs and has been tested up through 12-dimentional spheres.
The patch dispatches to rejection for Dim<8, transform otherwise as 
discussed earlier.


Builds and tests cleanly on x86_64-linux.

OK?

Ed

Index: include/ext/random
===
--- include/ext/random  (revision 241499)
+++ include/ext/random  (working copy)
@@ -3493,6 +3493,218 @@
   _RealType>& __d2)
 { return !(__d1 == __d2); }
 
+
+  /**
+   * @brief A distribution for random coordinates inside a unit sphere.
+   */
+  template
+class uniform_inside_sphere_distribution
+{
+  static_assert(std::is_floating_point<_RealType>::value,
+   "template argument not a floating point type");
+  static_assert(_Dimen != 0, "dimension is zero");
+
+public:
+  /** The type of the range of the distribution. */
+  using result_type = std::array<_RealType, _Dimen>;
+
+  /** Parameter type. */
+  struct param_type
+  {
+   using distribution_type
+ = uniform_inside_sphere_distribution<_Dimen, _RealType>;
+   friend class uniform_inside_sphere_distribution<_Dimen, _RealType>;
+
+   explicit
+   param_type(_RealType __radius = _RealType(1))
+   : _M_radius(__radius)
+   {
+ _GLIBCXX_DEBUG_ASSERT(_M_radius > _RealType(0));
+   }
+
+   _RealType
+   radius() const
+   { return _M_radius; }
+
+   friend bool
+   operator==(const param_type& __p1, const param_type& __p2)
+   { return __p1._M_radius == __p2._M_radius; }
+
+  private:
+   _RealType _M_radius;
+  };
+
+  /**
+   * @brief Constructors.
+   */
+  explicit
+  uniform_inside_sphere_distribution(_RealType __radius = _RealType(1))
+  : _M_param(__radius), _M_uosd()
+  { }
+
+  explicit
+  uniform_inside_sphere_distribution(const param_type& __p)
+  : _M_param(__p), _M_uosd()
+  { }
+
+  /**
+   * @brief Resets the distribution state.
+   */
+  void
+  reset()
+  { _M_uosd.reset(); }
+
+  /**
+   * @brief Returns the @f$radius@f$ of the distribution.
+   */
+  _RealType
+  radius() const
+  { return _M_param.radius(); }
+
+  /**
+   * @brief Returns the parameter set of the distribution.
+   */
+  param_type
+  param() const
+  { return _M_param; }
+
+  /**
+   * @brief Sets the parameter set of the distribution.
+   * @param __param The new parameter set of the distribution.
+   */
+  void
+  param(const param_type& __param)
+  { _M_param = __param; }
+
+  /**
+   * @brief Returns the greatest lower bound value of the distribution.
+   * This function makes no sense for this distribution.
+   */
+  result_type
+  min() const
+  {
+   result_type __res;
+   __res.fill(0);
+   return __res;
+  }
+
+  /**
+   * @brief Returns the least upper bound value of the distribution.
+   * This function makes no sense for this distribution.
+   */
+  result_type
+  max() const
+  {
+   result_type __res;
+   __res.fill(0);
+   return __res;
+  }
+
+  /**
+   * @brief Generating functions.
+   */
+  template
+   result_type
+   operator()(_UniformRandomNumberGenerator& __urng)
+   { return this->operator()(__urng, _M_param); }
+
+  template
+   result_type
+   operator()(_UniformRandomNumberGenerator& __urng,
+  const param_type& __p);
+
+  template
+   void
+   __generate(_ForwardIterator __f, _ForwardIterator __t,
+  _UniformRandomNumberGenerator& __urng)
+   { this->__generate(__f, __t, __urng, this->param()); }
+
+  template
+   void
+   __generate(_ForwardIterator __f, _ForwardIterator __t,
+  _UniformRandomNumberGenerator& __urng,
+  const param_type& __p)
+   { this->__generate_impl(__f, __t, __urng, __p); }
+
+  template
+   void
+   __generate(result_type* __f, result_type* __t,
+  _UniformRandomNumberGenerator& __urng,
+  const param_type& __p)
+   { this->__generate_impl(__f, __t, __urng, __p); }
+
+  /**
+   * @brief Return true if two uniform on sphere distributions have
+   *the same parameters and the sequences that would be
+   *generated are equal.
+   */
+  friend bool
+  operator==(const uniform_inside_sphere_distribution& __d1,
+const uniform_inside_sphere_distribution& __d2)
+  { return __d1._M_param == __d2._M_param && __d1._M_uosd == __d2._M_uosd; 
}
+
+  /**
+   * @brief Inserts a %uniform_inside_sphere_distribution random number
+   *distribution @p __x into the output stream @p __os.
+   *
+   * @param 

[libstdc++, C++17] Implement C++17 P0330 size_t UDL.

2016-07-20 Thread Ed Smith-Rowland

This patch defines

  operator""zu(unsigned long long __n)

for size_t literals.

for (auto k = 0zul; k < v.size(); ++k)

   ...


Testing on x86-64-linux is finishing but I'm past these tests.

OK?


Ed


2016-07-21  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++17 P0330 size_t UDL.
* include/c_global/cstddef: Add size_t operator""zu().
* testsuite/18_support/headers/cstddef/literals/types.cc: New test.
* testsuite/18_support/headers/cstddef/literals/values.cc: New test.

Index: include/c_global/cstddef
===
--- include/c_global/cstddef(revision 238557)
+++ include/c_global/cstddef(working copy)
@@ -57,4 +57,20 @@
 }
 #endif
 
+#if __cplusplus >= 201500L
+#define __cpp_lib_support_udls 201605
+namespace std
+{
+inline namespace literals
+{
+inline namespace support_literals
+{
+  constexpr size_t
+  operator""zu(unsigned long long __n)
+  { return static_cast(__n); }
+}
+}
+}
+#endif // C++17
+
 #endif // _GLIBCXX_CSTDDEF
Index: testsuite/18_support/headers/cstddef/literals/types.cc
===
--- testsuite/18_support/headers/cstddef/literals/types.cc  (nonexistent)
+++ testsuite/18_support/headers/cstddef/literals/types.cc  (working copy)
@@ -0,0 +1,31 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// 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
+// .
+
+#include 
+#include 
+
+void
+test01()
+{
+  using namespace std::literals::support_literals;
+
+  static_assert(std::is_same::value,
+   "1zu is std::size_t");
+}
Index: testsuite/18_support/headers/cstddef/literals/values.cc
===
--- testsuite/18_support/headers/cstddef/literals/values.cc (nonexistent)
+++ testsuite/18_support/headers/cstddef/literals/values.cc (working copy)
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++1z" }
+// { dg-do run }
+
+// 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
+// .
+
+#include 
+#include 
+#include 
+
+void
+test01()
+{
+  using namespace std::literals::support_literals;
+  bool test [[gnu::unused]] = true;
+
+  std::size_t s = 1zu;
+  std::size_t t = -1zu;
+
+  VERIFY( s == 1 );
+  VERIFY( t == std::numeric_limits::max() );
+}
+
+int
+main()
+{
+  test01();
+}


Re: [libstdc++] Add C++17clamp

2016-07-15 Thread Ed Smith-Rowland



OK for trunk, thanks.


I didn't see a feature test in any of the SD-6 papers or P0025.


p0096r3 proposes __cpp_lib_clamp = 201603.

I added the feature macro and committed the attached as 238383.

Thanks,

Ed

2016-07-15  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++17 P0025 clamp.
* include/bits/algorithmfwd.h: Declare clamp overloads.
* include/bits/stl_algo.h: Implement clamp.  Feature __cpp_lib_clamp.
* testsuite/25_algorithms/clamp/1.cc: New test.
* testsuite/25_algorithms/clamp/2.cc: New test.
* testsuite/25_algorithms/clamp/constexpr.cc: New test.
* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/
1.cc: New test.
* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/
pod.cc: New test.

Index: include/bits/algorithmfwd.h
===
--- include/bits/algorithmfwd.h (revision 238382)
+++ include/bits/algorithmfwd.h (revision 238383)
@@ -48,6 +48,7 @@
 all_of (C++0x)
 any_of (C++0x)
 binary_search
+clamp (C++17)
 copy
 copy_backward
 copy_if (C++0x)
@@ -208,6 +209,18 @@
 bool 
 binary_search(_FIter, _FIter, const _Tp&, _Compare);
 
+#if __cplusplus > 201402L
+  template
+_GLIBCXX14_CONSTEXPR
+const _Tp&
+clamp(const _Tp&, const _Tp&, const _Tp&);
+
+  template
+_GLIBCXX14_CONSTEXPR
+const _Tp&
+clamp(const _Tp&, const _Tp&, const _Tp&, _Compare);
+#endif
+
   template
 _OIter 
 copy(_IIter, _IIter, _OIter);
Index: include/bits/stl_algo.h
===
--- include/bits/stl_algo.h (revision 238382)
+++ include/bits/stl_algo.h (revision 238383)
@@ -3698,8 +3698,47 @@
   return std::__is_permutation(__first1, __last1, __first2, __last2,
   __gnu_cxx::__ops::__iter_comp_iter(__pred));
 }
-#endif
 
+#if __cplusplus > 201402L
+
+#define __cpp_lib_clamp 201603
+
+  /**
+   *  @brief  Returns the value clamped between lo and hi.
+   *  @ingroup sorting_algorithms
+   *  @param  __val  A value of arbitrary type.
+   *  @param  __lo   A lower limit of arbitrary type.
+   *  @param  __hi   An upper limit of arbitrary type.
+   *  @return max(__val, __lo) if __val < __hi or min(__val, __hi) otherwise.
+   */
+  template
+constexpr const _Tp&
+clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi)
+{
+  __glibcxx_assert(!(__hi < __lo));
+  return (__val < __lo) ? __lo : (__hi < __val) ? __hi : __val;
+}
+
+  /**
+   *  @brief  Returns the value clamped between lo and hi.
+   *  @ingroup sorting_algorithms
+   *  @param  __val   A value of arbitrary type.
+   *  @param  __loA lower limit of arbitrary type.
+   *  @param  __hiAn upper limit of arbitrary type.
+   *  @param  __comp  A comparison functor.
+   *  @return max(__val, __lo, __comp) if __comp(__val, __hi)
+   * or min(__val, __hi, __comp) otherwise.
+   */
+  template
+constexpr const _Tp&
+clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
+{
+  __glibcxx_assert(!__comp(__hi, __lo));
+  return __comp(__val, __lo) ? __lo : __comp(__hi, __val) ? __hi : __val;
+}
+#endif // C++17
+#endif // C++14
+
 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
   /**
*  @brief Shuffle the elements of a sequence using a uniform random
Index: testsuite/25_algorithms/clamp/1.cc
===
--- testsuite/25_algorithms/clamp/1.cc  (nonexistent)
+++ testsuite/25_algorithms/clamp/1.cc  (revision 238383)
@@ -0,0 +1,48 @@
+// { dg-options "-std=gnu++17" }
+
+// 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
+// .
+
+#include 
+#include 
+#include 
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  const int x = std::clamp(1, 2, 4);
+  const int y = std::clamp(3, 2, 4);
+  const int z = std::clamp(5, 2, 4);
+  VERIFY( x == 2 );
+  VERIFY( y == 3 );
+  VERIFY( z == 4 );
+
+  const int xc = std::clamp(1, 2, 4, std::greater());
+  const int yc = std::clamp(3, 2, 4, std::greater());
+  const int zc = std::clamp(5, 2, 4, std::greater());
+  VERIFY( xc == 4 );
+  VERIFY( yc == 2 );
+  

[libstdc++] Add C++17clamp

2016-07-14 Thread Ed Smith-Rowland

Here is an implementation of P0025
An algorithm to "clamp" a value between a pair of boundary values.

Testing is almost finished - looks good so far.

OK if testing passes?

I didn't see a feature test in any of the SD-6 papers or P0025.


2016-07-15  Edward Smith-Rowland  <3dw...@verizon.net>

Implement C++17 P0025 clamp.
* include/bits/algorithmfwd.h: Declare clamp overloads.
* include/bits/stl_algo.h: Implement clamp.
* testsuite/25_algorithms/clamp/1.cc: New test.
* testsuite/25_algorithms/clamp/2.cc: New test.
* testsuite/25_algorithms/clamp/constexpr.cc: New test.
* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/
1.cc: New test.
* testsuite/25_algorithms/clamp/requirements/explicit_instantiation/
pod.cc: New test.
Index: include/bits/algorithmfwd.h
===
--- include/bits/algorithmfwd.h (revision 238302)
+++ include/bits/algorithmfwd.h (working copy)
@@ -48,6 +48,7 @@
 all_of (C++0x)
 any_of (C++0x)
 binary_search
+clamp (C++17)
 copy
 copy_backward
 copy_if (C++0x)
@@ -208,6 +209,18 @@
 bool 
 binary_search(_FIter, _FIter, const _Tp&, _Compare);
 
+#if __cplusplus > 201402L
+  template
+_GLIBCXX14_CONSTEXPR
+const _Tp&
+clamp(const _Tp&, const _Tp&, const _Tp&);
+
+  template
+_GLIBCXX14_CONSTEXPR
+const _Tp&
+clamp(const _Tp&, const _Tp&, const _Tp&, _Compare);
+#endif
+
   template
 _OIter 
 copy(_IIter, _IIter, _OIter);
Index: include/bits/stl_algo.h
===
--- include/bits/stl_algo.h (revision 238302)
+++ include/bits/stl_algo.h (working copy)
@@ -3698,8 +3698,44 @@
   return std::__is_permutation(__first1, __last1, __first2, __last2,
   __gnu_cxx::__ops::__iter_comp_iter(__pred));
 }
-#endif
 
+#if __cplusplus > 201402L
+  /**
+   *  @brief  Returns the value clamped between lo and hi.
+   *  @ingroup sorting_algorithms
+   *  @param  __val  A value of arbitrary type.
+   *  @param  __lo   A lower limit of arbitrary type.
+   *  @param  __hi   An upper limit of arbitrary type.
+   *  @return max(__val, __lo) if __val < __hi or min(__val, __hi) otherwise.
+   */
+  template
+constexpr const _Tp&
+clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi)
+{
+  __glibcxx_assert(!(__hi < __lo));
+  return (__val < __lo) ? __lo : (__hi < __val) ? __hi : __val;
+}
+
+  /**
+   *  @brief  Returns the value clamped between lo and hi.
+   *  @ingroup sorting_algorithms
+   *  @param  __val   A value of arbitrary type.
+   *  @param  __loA lower limit of arbitrary type.
+   *  @param  __hiAn upper limit of arbitrary type.
+   *  @param  __comp  A comparison functor.
+   *  @return max(__val, __lo, __comp) if __comp(__val, __hi)
+   * or min(__val, __hi, __comp) otherwise.
+   */
+  template
+constexpr const _Tp&
+clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
+{
+  __glibcxx_assert(!__comp(__hi, __lo));
+  return __comp(__val, __lo) ? __lo : __comp(__hi, __val) ? __hi : __val;
+}
+#endif // C++17
+#endif // C++14
+
 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
   /**
*  @brief Shuffle the elements of a sequence using a uniform random
Index: testsuite/25_algorithms/clamp/1.cc
===
--- testsuite/25_algorithms/clamp/1.cc  (nonexistent)
+++ testsuite/25_algorithms/clamp/1.cc  (working copy)
@@ -0,0 +1,48 @@
+// { dg-options "-std=gnu++17" }
+
+// 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
+// .
+
+#include 
+#include 
+#include 
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  const int x = std::clamp(1, 2, 4);
+  const int y = std::clamp(3, 2, 4);
+  const int z = std::clamp(5, 2, 4);
+  VERIFY( x == 2 );
+  VERIFY( y == 3 );
+  VERIFY( z == 4 );
+
+  const int xc = std::clamp(1, 2, 4, std::greater());
+  const int yc = std::clamp(3, 2, 4, std::greater());
+  const int zc = std::clamp(5, 2, 4, std::greater());
+  VERIFY( xc == 4 );
+  VERIFY( yc == 2 );
+  VERIFY( zc == 2 );
+}
+
+int
+main()
+{
+  

Edit the C++14 library warning header to not indicate experimental.

2016-04-17 Thread Ed Smith-Rowland


Since the default is C++14 it seems apropos to *not* treat that C++ 
version thusly in the warning in libstdc++.

Ed

OK for trunk?  And maybe some 6 branch later?

2016-04-17  Edward Smith-Rowland  <3dw...@verizon.net>

* include/bits/c++14_warning.h: Do not refer C++14 as experimental.

Index: include/bits/c++14_warning.h
===
--- include/bits/c++14_warning.h(revision 235086)
+++ include/bits/c++14_warning.h(working copy)
@@ -29,9 +29,9 @@
 #define _CXX14_WARNING_H 1
 
 #if __cplusplus <= 201103L
-#error This file requires compiler and library support for the forthcoming \
-ISO C++ 2014 standard. This support is currently experimental, and must be \
-enabled with the -std=c++1y or -std=gnu++1y compiler options.
+#error This file requires compiler and library support \
+for the ISO C++ 2014 standard. This support must be enabled \
+with the -std=c++14 or -std=gnu++14 compiler options.
 #endif
 
 #endif


Document C++ Special Math Functions.

2016-04-08 Thread Ed Smith-Rowland
I wanted to ship the TR29124 special math functions in libstdc++ with 
some documentation.
More could be done but this covers the function definitions, argument 
ranges, template parms, and arguments.

There is a little mainpage with some overview, history, biblio, and links.

2016-04-08  Edward Smith-Rowland  <3dw...@verizon.net>

Document C++19/TR29124 C++ Special Math Functions.
* include/bits/specfun.h: Add Doxygen markup.
Index: include/bits/specfun.h
===
--- include/bits/specfun.h  (revision 234525)
+++ include/bits/specfun.h  (working copy)
@@ -75,16 +75,182 @@
* @{
*/
 
+  /**
+   * @mainpage Mathematical Special Functions
+   *
+   * @section intro Introduction and History
+   * The first significant library upgrade on the road to C++2011,
+   * http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1836.pdf;>
+   * TR1, included a set of 23 mathematical functions that significntly
+   * extended the standard trancendental functions inherited from C and 
declared
+   * in @.
+   *
+   * Although most components from TR1 were eventually adopted for C++11 these
+   * math function were left behind out of concern for implementability.
+   * The math functions were published as a separate international standard
+   * http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2010/n3060.pdf;>
+   * IS 29124 - Extensions to the C++ Library to Support Mathematical Special
+   * Functions.
+   *
+   * For C++17 these functions were incorporated into the main standard.
+   *
+   * @section contents Contents
+   * The folowing functions are implemented in namespace @c std:
+   * - @ref assoc_laguerre "assoc_laguerre - Associated Laguerre functions"
+   * - @ref assoc_legendre "assoc_legendre - Associated Legendre functions"
+   * - @ref beta "beta - Beta functions"
+   * - @ref comp_ellint_1 "comp_ellint_1 - Complete elliptic functions of the 
first kind"
+   * - @ref comp_ellint_2 "comp_ellint_2 - Complete elliptic functions of the 
second kind"
+   * - @ref comp_ellint_3 "comp_ellint_3 - Complete elliptic functions of the 
third kind"
+   * - @ref cyl_bessel_i "cyl_bessel_i - Regular modified cylindrical Bessel 
functions"
+   * - @ref cyl_bessel_j "cyl_bessel_j - Cylindrical Bessel functions of the 
first kind"
+   * - @ref cyl_bessel_k "cyl_bessel_k - Irregular modified cylindrical Bessel 
functions"
+   * - @ref cyl_neumann "cyl_neumann - Cylindrical Neumann functions or 
Cylindrical Bessel functions of the second kind"
+   * - @ref ellint_1 "ellint_1 - Incomplete elliptic functions of the first 
kind"
+   * - @ref ellint_2 "ellint_2 - Incomplete elliptic functions of the second 
kind"
+   * - @ref ellint_3 "ellint_3 - Incomplete elliptic functions of the third 
kind"
+   * - @ref expint "expint - The exponential integral"
+   * - @ref hermite "hermite - Hermite polynomials"
+   * - @ref laguerre "laguerre - Laguerre functions"
+   * - @ref legendre "legendre - Legendre polynomials"
+   * - @ref riemann_zeta "riemann_zeta - The Riemann zeta function"
+   * - @ref sph_bessel "sph_bessel - Spherical Bessel functions"
+   * - @ref sph_legendre "sph_legendre - Spherical Legendre functions"
+   * - @ref sph_neumann "sph_neumann - Spherical Neumann functions"
+   *
+   * The hypergeometric functions were stricken from the TR29124 and C++17
+   * versions of this math library because of implementation concerns.
+   * However, since they were in the TR1 version and since they are popular
+   * we kept them as an extension in namespace @c __gnu_cxx:
+   * - @ref conf_hyperg "conf_hyperg - Confluent hypergeometric functions"
+   * - @ref hyperg "hyperg - Hypergeometric functions"
+   *
+   * @section general General Features
+   *
+   * @subsection "Argument Promotion"
+   * The arguments suppled to the non-suffixed functions will be promoted
+   * according to the following rules:
+   * 1. If any argument intended to be floating opint is given an integral 
value
+   * That integral value is promoted to double.
+   * 2. All floating point arguments are promoted up to the largest floating
+   *point precision among them.
+   *
+   * @subsection NaN NaN Arguments
+   * If any of the floating point arguments supplied to these functions is
+   * invalid or NaN (std::numeric_limits::quiet_NaN),
+   * the value NaN is returned.
+   *
+   * @section impl Implementation
+   *
+   * We strive to implement the underlying math with type generic algorithms
+   * to the greatest extent possible.  In practice, the function are thin
+   * wrappers that dispatch to function templates. Type dependence is
+   * controlled with std::numeric_limits and functions thereof.
+   *
+   * We don't promote *c float to *c double or *c double to long 
double
+   * reflexively.  The goal is for float functions to operate more quickly,
+   * at the cost of float accuracy and possibly a smaller domain of validity.
+   * Similaryly, long 

Re: Add C++ special math functions to C++17

2016-03-11 Thread Ed Smith-Rowland

On 03/11/2016 10:55 AM, Jonathan Wakely wrote:

The change approved in Jacksonville was to only add the special
functions to  and not 


That's easy.
OK, since they changed that and the macro and made it nonconditional I 
should also drop the old-style macros __WANT_MATH_CANNEVERREMEMBER__ and 
the old-style version macro.
So, in other words, we're *not* actually supporting TR29124 (that's fine 
by me).

We can tweak the web pages.
People on C++11, C++14 can use tr1.

Did they keep the Cisms like:

  float
  foobarf(float x);

  double
  foobar(double x);

  long double
  foobarl(long double x);

I am keeping an eye out for the words of the draft github.
Maybe I'll ping Axel and Walter.

Ed



  1   2   3   4   >