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  >
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 "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; 

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

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 implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" Z(unsigned long long int k)  // { dg-warning "integer 

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"" 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" }
+{ 

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 of the GNU ISO C++ Library.  This library is free
+// software; you can 

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,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 

[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,12 @@
   // mismatch
 
   template
+

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);
 
@@ -590,6 +605,7 @@ 

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,
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);
 
@@ -579,6 +593,7 @@ 

[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.
* 

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
+// .
+
+#include 
+#include 
+
+constexpr char
+test()
+{
+  constexpr std::string_view hw("Hello, World!");
+  static_assert('H' == *hw.begin());
+  auto ch = hw[4];
+  static_assert('W' 

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
+// .
+
+#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
+// .
+
+#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
+// .
+
+#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
+// .
+
+#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
+// .
+
+#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, mismatch): 

[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_iterators/69478.cc:
Prune "deleted".

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 _GLIBCXX_USE_CONSTEXPR int max_exponent10 = FLT128_MAX_10_EXP;
+
+  static 

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_compare::__lc, 

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