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

2021-02-04 Thread Jason Merrill via Gcc-patches

On 2/4/21 11:27 AM, Ed Smith-Rowland wrote:

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


It seems reasonable for the date in the standard to be later than the 
date in the proposal paper.



Jason, is this OK?


OK.

Jason



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


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

2021-02-04 Thread Tam S. B. via Gcc-patches
`__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


From: Gcc-patches  on behalf of Ed 
Smith-Rowland via Gcc-patches 
Sent: Tuesday, February 2, 2021 6:19
To: Jason Merrill; Jakub Jelinek
Cc: gcc-patches; nat...@acm.org; Joseph S. Myers
Subject: Re: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for 
ptrdiff_t and size_t

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_T0x200 /* 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




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

2021-02-02 Thread Jason Merrill via Gcc-patches

On 2/2/21 1:19 AM, Ed Smith-Rowland wrote:

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.



+++ b/gcc/testsuite/g++.dg/warn/Wsize_t-literals.C
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++20_down } }
+
+#if __cplusplus >= 201103L
+
+#include 
+#include 
+
+std::size_t s1 = 1234zu; // { dg-warning {use of C\+\+23 .size_t. integer constant} 
"" { target { ! c++98_only } } }
+std::size_t S1 = 5678ZU; // { dg-warning {use of C\+\+23 .size_t. integer constant} 
"" { target { ! c++98_only } } }
+std::size_t s2 = 1234uz; // { dg-warning {use of C\+\+23 .size_t. integer constant} 
"" { target { ! c++98_only } } }
+std::size_t S2 = 5678UZ; // { dg-warning {use of C\+\+23 .size_t. integer constant} 
"" { target { ! c++98_only } } }
+
+std::make_signed::type pd1 = 1234z; // { dg-warning {use of C\+\+23 
.make_signed::type. integer constant} "" { target { ! c++98_only } } }
+std::make_signed::type PD1 = 5678Z; // { dg-warning {use of C\+\+23 
.make_signed::type. integer constant} "" { target { ! c++98_only } } }
+
+#endif


I'd suggest switching the target constraints around: use target c++11 in 
the dg-do line, drop the #if, and use target c++20_down in the 
diagnostics.  OK with that change.


Jason



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 Jason Merrill via Gcc-patches

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



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 Jakub Jelinek via Gcc-patches
On Mon, Feb 01, 2021 at 08:23:18PM +0100, Jakub Jelinek via Gcc-patches 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

Or better std::make_signed_t etc.

Jakub



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

2021-02-01 Thread Jason Merrill via Gcc-patches

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

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:


Yes, but the final proposal specifies a suffix for signed size_t, not 
ptrdiff_t.



ssize_t:
   signed_size_type_node = c_common_signed_type (size_type_node);


Ah, I wasn't aware of signed_size_type_node, that's better than my 
suggestion of calling c_common_signed_type again.


Jason



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

2021-02-01 Thread Jakub Jelinek via Gcc-patches
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

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

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

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



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-02-01 Thread Jason Merrill via Gcc-patches

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;


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.


Jason



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: [[C++ PATCH]] Implement C++2a P0330R2 - Literal Suffixes for ptrdiff_t and size_t

2021-01-27 Thread Jakub Jelinek via Gcc-patches
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



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

2018-10-23 Thread Florian Weimer
* Ed Smith-Rowland:

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

So a plain z would denote ptrdiff_t, and size_t would be zu?  That is
very confusing.

Why is this not consistent with %td, %zd and %zu?  I would have expected
t for ptrdiff_t, zu for size_t, and z for ssize_t.

Thanks,
Florian


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

2018-10-22 Thread Joseph Myers
On Mon, 22 Oct 2018, Jason Merrill wrote:

> > I'm thinking of making this feature available as an extension to all of
> > C/C++ perhaps with appropriate pedwarn.
> > 
> > Opinions?
> 
> That seems reasonable to me, but Joseph will need to weigh in about C.

A C extension would seem reasonable, if documented as such in the manual 
(and with pedwarns tested in the testsuite, etc.).  (The patch is also 
missing invoke.texi updates for the new command-line option, in any case.)

-- 
Joseph S. Myers
jos...@codesourcery.com


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

2018-10-22 Thread Jason Merrill

On 10/21/18 4:39 PM, Ed Smith-Rowland wrote:

All,

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


I don't mind putting it in before it passes so long as you keep track of 
the proposal's progress -- I just discovered that the string UDL 
template proposal we implemented for C++14 wasn't actually accepted, so 
we need to pedwarn about it.


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


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


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


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


Opinions?


That seems reasonable to me, but Joseph will need to weigh in about C.

Jason



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

2018-10-21 Thread Ed Smith-Rowland

All,

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


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


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


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


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


Opinions?

Ed Smith-Rowland

[*] http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0330r2.html


Index: gcc/c-family/c-cppbuiltin.c
===
--- gcc/c-family/c-cppbuiltin.c (revision 265343)
+++ gcc/c-family/c-cppbuiltin.c (working copy)
@@ -975,6 +975,11 @@
  cpp_define (pfile, "__cpp_structured_bindings=201606");
  cpp_define (pfile, "__cpp_variadic_using=201611");
}
+  if (cxx_dialect > cxx17)
+   {
+ /* Set feature test macros for C++2a.  */
+ cpp_define (pfile, "__cpp_ptrdiff_t_suffix=201811");
+   }
   if (flag_concepts)
cpp_define (pfile, "__cpp_concepts=201507");
   if (flag_tm)
Index: gcc/c-family/c-lex.c
===
--- gcc/c-family/c-lex.c(revision 265343)
+++ gcc/c-family/c-lex.c(working copy)
@@ -766,6 +766,14 @@
 type = ((flags & CPP_N_UNSIGNED)
? widest_unsigned_literal_type_node
: widest_integer_literal_type_node);
+  else if (flags & CPP_N_PTRDIFF_T)
+{
+  /* itk refers to fundamental types not aliased size types.  */
+  if (flags & CPP_N_UNSIGNED)
+   type = size_type_node;
+  else
+   type = ptrdiff_type_node;
+}
   else
 {
   type = integer_types[itk];
Index: gcc/c-family/c.opt
===
--- gcc/c-family/c.opt  (revision 265343)
+++ gcc/c-family/c.opt  (working copy)
@@ -699,6 +699,10 @@
 C ObjC C++ ObjC++ CPP(cpp_warn_long_long) CppReason(CPP_W_LONG_LONG) 
Var(warn_long_long) Init(-1) Warning LangEnabledBy(C ObjC,Wc90-c99-compat)
 Do not warn about using \"long long\" when -pedantic.
 
+Wptrdiff_t-literals
+C ObjC C++ ObjC++ CPP(ptrdiff_t_literals) CppReason(CPP_W_PTRDIFF_T_LITERALS) 
Var(warn_ptrdiff_t_literals) Init(1) Warning LangEnabledBy(C ObjC C++ ObjC++)
+Warn when \"z\" or \"Z\" is used as a numeric literal suffix for C or C++yy, 
yy <= 17.
+
 Wmain
 C ObjC C++ ObjC++ Var(warn_main) Init(-1) Warning LangEnabledBy(C ObjC,Wall, 
2, 0)
 Warn about suspicious declarations of \"main\".
Index: gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C
===
--- gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C   (revision 265343)
+++ gcc/testsuite/g++.dg/cpp0x/udlit-shadow-neg.C   (working copy)
@@ -17,6 +17,30 @@
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" uz(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" zu(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" Z(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" UZ(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
+unsigned long long int
+operator"" ZU(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
+{ return k; }
+
 //  Namespaces are no hiding place.
 namespace Long
 {
@@ -37,6 +61,30 @@
 operator"" ull(unsigned long long int k)  // { dg-warning "integer 
suffix|shadowed by implementation" }
 { return k; }
 
+unsigned long long int
+operator"" z(unsigned long long int k)  // { dg-warning "integer 
suffix|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