Re: [PATCH v2] c++: Add support for -std=c++2b

2021-01-24 Thread Paul Fee via Gcc-patches
On Tue, Jan 19, 2021 at 11:28 PM Jason Merrill  wrote:
>
> On 1/10/21 7:28 PM, Paul Fee via Gcc-patches wrote:
> > [PATCH v2] c++: Add support for -std=c++2b
>
> Thanks!
>
> This patch was corrupted by word wrap, so it won't apply; if you can't
> suppress word wrap in your mail client, please send the patch as an
> attachment instead.
Seems that "Plain text mode" in gmail isn't plain enough.  I'll use an
attachment for patch v3.
>
> Also remember to use git gcc-verify before sending the patch.
Thanks for the tip.  It helps me learn the GCC patch posting process.
>
> > Derived from the changes that added C++2a support in 2017.
> > https://gcc.gnu.org/g:026a79f70cf33f836ea5275eda72d4870a3041e5
> >
> > No C++2b features are added here.
> > Use of -std=c++2b sets __cplusplus to 202100L.
> >
> > $ g++ -std=c++2b -dM -E -x c++ - < /dev/null | grep cplusplus
> > #define __cplusplus 202100L
> >
> > Changes since v1 (8th Jan 2021):
> > * As suggested by Jonathan Wakely:
> >__cplusplus set to 202100L rather than 202101L.  Use of a non-existent 
> > date
> >helps indicate this is not a true standard, yet is a value greater
> > than 202002L.
> > * As suggested by Jakub Jelinek:
> >Fixed typos and formatting.
> >Added C++23 support to dwarf2out.c, including missing C++20 support
> > in highest_c_language.
>
> > * Regarding suggestion by Marek Polacek to refer to C++23 rather than C++2b.
> >Left the option as -std=c++2b for now.  It may be premature to assume 
> > the next
> >version of the standard will be named C++23.  Use of c++2b also 
> > reinforces
> >the experimental nature of GCC's C++23 implementation.
>
> Hmm, I don't think it's that premature; the C++ committee has been very
> serious about time-based releases every three years.  I think it makes
> sense for the advertised flag to be c++2b, but let's also go ahead and
> add the c++23 flags as hidden, and use cxx23 internally.
Ok, I'll change from only exposing -std=c++2b to the end goal of
-std=c++23.  You pointed out below a flaw in target-supports.exp.
Checking "make check-c++", I found that I'd also broken many tests
while adjusting c++2a to be c++20.  I'll take the 2a->20 change out of
this patch.  It can be in a separate patch.  Seeing the cost of
changing from "2a" to "20", I'll post up patch v3 with support for
-std=c++23 so that a "2b->23" change isn't needed in a few years.
GCC's C++23 will still be experimental, despite the flag be
-std=c++23.
>
> > gcc/
> >
> >  Add support for -std=c++2b
> >  * doc/cpp.texi (__cplusplus): Document value for -std=c++2b
> >  or -std=gnu++2b.
> >  * doc/invoke.texi: Document -std=c++2b and -std=gnu++2b.
> >
> > gcc/c-family
> >
> >  Add support for -std=c++2b
> >  * c-common.h (cxx_dialect): Add cxx2b as a dialect.
> >  * c.opt: Add options for -std=c++2b and -std=gnu++2b.
> >  * c-opts.c (set_std_cxx2b): New.
> >  (c_common_handle_option): Set options when -std=c++2b is enabled.
> >  (c_common_post_options): Adjust comments.
> >  (set_std_cxx20): Likewise.
> >  * dwarf2out.c (highest_c_language): Recognise C++20 and C++23.
> >  (gen_compile_unit_die): Recognise C++23.
>
> dwarf2out.c isn't in c-family.
>
> > gcc/testsuite
> >
> >  Add support for -std=c++2b
> >  * lib/target-supports.exp (check_effective_target_c++2a_only):
> >  rename to check_effective_target_c++20_only.
> >  (check_effective_target_c++2a): rename to check_effective_target_c++20.
> >  (check_effective_target_c++20): Return 1
> >  if check_effective_target_c++20_only or
> >  if check_effective_target_c++2b.
> >  (check_effective_target_c++20_down): New.
> >  (check_effective_target_c++2a_only): New.
> >  (check_effective_target_c++2a): New.
> >  * g++.dg/cpp2b/cplusplus.C: New.
> >
> > libcpp
> >  Add support for -std=c++2b
> >  * include/cpplib.h (c_lang): Add CXX2B and GNUCXX2B.
> >  * init.c (lang_defaults): Add rows for CXX2B and GNUCXX2B.
> >  (cpp_init_builtins): Set __cplusplus to 202100L for C++2b.
> > ---
> >   gcc/c-family/c-common.h|4 ++-
> >   gcc/c-family/c-opts.c  |   29 ++--
> >   gcc/c-family/c.opt |8 ++
> >   gcc/doc/cpp.texi   |7 +++--
> >   gcc/doc/invoke.texi| 

[PATCH v3] c++: Add support for -std=c++23

2021-01-24 Thread Paul Fee via Gcc-patches
Derived from the changes that added C++2a support in 2017.
https://gcc.gnu.org/g:026a79f70cf33f836ea5275eda72d4870a3041e5

No C++23 features are added here.
Use of -std=c++23 sets __cplusplus to 202100L.

$ g++ -std=c++23 -dM -E -x c++ - < /dev/null | grep cplusplus
#define __cplusplus 202100L

Changes since v2 (11th Jan 2021):
* Dropped testsuite change (c++2a to c++20).
* As suggested by Marek Polacek and Jason Merrill
  Added -std=c++23 since three year cadence is well established.

Author: Paul Fee 
Date:   Mon Jan 25 00:12:03 2021 +

   Add support for -std=c++23

   gcc/

   * doc/cpp.texi (__cplusplus): Document value for -std=c++23
   or -std=gnu++23.
   * doc/invoke.texi: Document -std=c++23 and -std=gnu++23.
   * dwarf2out.c (highest_c_language): Recognise C++20 and C++23.
   (gen_compile_unit_die): Recognise C++23.

   gcc/c-family/

   * c-common.h (cxx_dialect): Add cxx23 as a dialect.
   * c.opt: Add options for -std=c++23, std=c++2b, -std=gnu++23
   and -std=gnu++2b
   * c-opts.c (set_std_cxx23): New.
   (c_common_handle_option): Set options when -std=c++23 is enabled.
   (c_common_post_options): Adjust comments.
   (set_std_cxx20): Likewise.

   gcc/testsuite/

   * lib/target-supports.exp (check_effective_target_c++2a):
   Check for C++2a or C++23.
   (check_effective_target_c++2a_down): New.
   (check_effective_target_c++20_down): New.
   (check_effective_target_c++23_only): New.
   (check_effective_target_c++23): New.
   * g++.dg/cpp23/cplusplus.C: New.

   libcpp/

   * include/cpplib.h (c_lang): Add CXX23 and GNUCXX23.
   * init.c (lang_defaults): Add rows for CXX23 and GNUCXX23.
   (cpp_init_builtins): Set __cplusplus to 202100L for C++23.
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index a65c78f7240..f30b6c6ac33 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -738,7 +738,9 @@ enum cxx_dialect {
   /* C++17 */
   cxx17,
   /* C++20 */
-  cxx20
+  cxx20,
+  /* C++23 */
+  cxx23
 };
 
 /* The C++ dialect being used. C++98 is the default.  */
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 3cdf41bc6e2..bd15b9cd902 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -113,6 +113,7 @@ static void set_std_cxx11 (int);
 static void set_std_cxx14 (int);
 static void set_std_cxx17 (int);
 static void set_std_cxx20 (int);
+static void set_std_cxx23 (int);
 static void set_std_c89 (int, int);
 static void set_std_c99 (int);
 static void set_std_c11 (int);
@@ -649,6 +650,12 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
 	set_std_cxx20 (code == OPT_std_c__20 /* ISO */);
   break;
 
+case OPT_std_c__23:
+case OPT_std_gnu__23:
+  if (!preprocessing_asm_p)
+	set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
+  break;
+
 case OPT_std_c90:
 case OPT_std_iso9899_199409:
   if (!preprocessing_asm_p)
@@ -1019,7 +1026,7 @@ c_common_post_options (const char **pfilename)
 	warn_narrowing = 1;
 
   /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
-	 for -std=c++{11,14,17,2a} default to -fno-ext-numeric-literals.  */
+	 for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals.  */
   if (flag_iso && !global_options_set.x_flag_ext_numeric_literals)
 	cpp_opts->ext_numeric_literals = 0;
 }
@@ -1763,7 +1770,7 @@ set_std_cxx20 (int iso)
   flag_no_gnu_keywords = iso;
   flag_no_nonansi_builtin = iso;
   flag_iso = iso;
-  /* C++17 includes the C11 standard library.  */
+  /* C++20 includes the C11 standard library.  */
   flag_isoc94 = 1;
   flag_isoc99 = 1;
   flag_isoc11 = 1;
@@ -1773,6 +1780,24 @@ set_std_cxx20 (int iso)
   lang_hooks.name = "GNU C++20";
 }
 
+/* Set the C++ 2023 standard (without GNU extensions if ISO).  */
+static void
+set_std_cxx23 (int iso)
+{
+  cpp_set_lang (parse_in, iso ? CLK_CXX23: CLK_GNUCXX23);
+  flag_no_gnu_keywords = iso;
+  flag_no_nonansi_builtin = iso;
+  flag_iso = iso;
+  /* C++23 includes the C11 standard library.  */
+  flag_isoc94 = 1;
+  flag_isoc99 = 1;
+  flag_isoc11 = 1;
+  /* C++23 includes coroutines.  */
+  flag_coroutines = true;
+  cxx_dialect = cxx23;
+  lang_hooks.name = "GNU C++23";
+}
+
 /* Args to -d specify what to dump.  Silently ignore
unrecognized options; they may be aimed at toplev.c.  */
 static void
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 1766364806e..880ab424d50 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2214,6 +2214,14 @@ std=c++20
 C++ ObjC++
 Conform to the ISO 2020 C++ draft standard (experimental and incomplete support).
 
+std=c++2b
+C++ ObjC++ Alias(std=c++23) Undocumented
+Conform to the ISO 2020 C++ draft standard (experimental and incomplete support).
+
+std=c++23
+C++ ObjC++
+Conform to the ISO 2023 C++ draft standard (experimental and incomplete suppor

[PATCH] c++: Add support for -std=c++2b

2021-01-07 Thread Paul Fee via Gcc-patches
Derived from the changes that added C++2a support in 2017.
https://gcc.gnu.org/g:026a79f70cf33f836ea5275eda72d4870a3041e5

No C++2b features are added here.
Use of -std=c++2b sets __cplusplus to 202101L.


diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5541e694bb3..3a0d452b62b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2021-01-08  Paul Fee  
+
+Add support for -std=c++2b
+* doc/cpp.texi (__cplusplus): Document value for -std=c++2b
+or -std=gnu+2b.
+* doc/invoke.texi: Document -std=c++2b and -std=gnu++2b.
+
 2021-01-06  Vladimir N. Makarov  

 PR rtl-optimization/97978
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 654c2360085..9af4050fdc8 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,13 @@
+2021-01-08  Paul Fee  
+
+Add support for -std=c++2b
+* c-common.h (cxx_dialect): Add cxx2b as a dialect.
+* c.opt: Add options for -std=c++2b and -std=gnu++2b.
+* c-opts.c (set_std_cxx2b): New.
+(c_common_handle_option): Set options when -std=c++2b is enabled.
+(c_common_post_options): Adjust comments.
+(set_std_cxx20): Likewise.
+
 2021-01-06  Martin Sebor  

 PR c++/95768
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index a65c78f7240..cfa056a6e28 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -738,7 +738,9 @@ enum cxx_dialect {
   /* C++17 */
   cxx17,
   /* C++20 */
-  cxx20
+  cxx20,
+  /* C++23? */
+  cxx2b
 };

 /* The C++ dialect being used. C++98 is the default.  */
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 3cdf41bc6e2..2612fac5a62 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -113,6 +113,7 @@ static void set_std_cxx11 (int);
 static void set_std_cxx14 (int);
 static void set_std_cxx17 (int);
 static void set_std_cxx20 (int);
+static void set_std_cxx2b (int);
 static void set_std_c89 (int, int);
 static void set_std_c99 (int);
 static void set_std_c11 (int);
@@ -649,6 +650,12 @@ c_common_handle_option (size_t scode, const char
*arg, HOST_WIDE_INT value,
 set_std_cxx20 (code == OPT_std_c__20 /* ISO */);
   break;

+case OPT_std_c__2b:
+case OPT_std_gnu__2b:
+  if (!preprocessing_asm_p)
+set_std_cxx2b (code == OPT_std_c__2b /* ISO */);
+  break;
+
 case OPT_std_c90:
 case OPT_std_iso9899_199409:
   if (!preprocessing_asm_p)
@@ -1019,7 +1026,7 @@ c_common_post_options (const char **pfilename)
 warn_narrowing = 1;

   /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
- for -std=c++{11,14,17,2a} default to -fno-ext-numeric-literals.  */
+ for -std=c++{11,14,17,20,2b} default to -fno-ext-numeric-literals.  */
   if (flag_iso && !global_options_set.x_flag_ext_numeric_literals)
 cpp_opts->ext_numeric_literals = 0;
 }
@@ -1763,7 +1770,7 @@ set_std_cxx20 (int iso)
   flag_no_gnu_keywords = iso;
   flag_no_nonansi_builtin = iso;
   flag_iso = iso;
-  /* C++17 includes the C11 standard library.  */
+  /* C++20 includes the C11 standard library.  */
   flag_isoc94 = 1;
   flag_isoc99 = 1;
   flag_isoc11 = 1;
@@ -1773,6 +1780,24 @@ set_std_cxx20 (int iso)
   lang_hooks.name = "GNU C++20";
 }

+/* Set the C++ 2020 standard (without GNU extensions if ISO).  */
+static void
+set_std_cxx2b (int iso)
+{
+cpp_set_lang (parse_in, iso ? CLK_CXX2B: CLK_GNUCXX2B);
+flag_no_gnu_keywords = iso;
+flag_no_nonansi_builtin = iso;
+flag_iso = iso;
+/* C++2b includes the C11 standard library.  */
+flag_isoc94 = 1;
+flag_isoc99 = 1;
+flag_isoc11 = 1;
+/* C++2b includes coroutines.  */
+flag_coroutines = true;
+cxx_dialect = cxx2b;
+lang_hooks.name = "GNU C++20"; /* Pretend C++20 until standardization.  */
+}
+
 /* Args to -d specify what to dump.  Silently ignore
unrecognized options; they may be aimed at toplev.c.  */
 static void
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 1766364806e..3464d72591b 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2214,6 +2214,11 @@ std=c++20
 C++ ObjC++
 Conform to the ISO 2020 C++ draft standard (experimental and
incomplete support).

+std=c++2b
+C++ ObjC++
+Conform to the ISO 2023 (?) C++ draft standard (experimental and
+incomplete support).
+
 std=c11
 C ObjC
 Conform to the ISO 2011 C standard.
@@ -2292,6 +2297,11 @@ std=gnu++20
 C++ ObjC++
 Conform to the ISO 2020 C++ draft standard with GNU extensions
(experimental and incomplete support).

+std=gnu++2b
+C++ ObjC++
+Conform to the ISO 2023 (?) C++ draft standard with GNU extensions
(experimental
+and incomplete support).
+
 std=gnu11
 C ObjC
 Conform to the ISO 2011 C standard with GNU extensions.
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 25f2625d8bd..f801024affd 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -1907,9 +1907,10 @@ selected, the value of the macro is
 @code{201103L} for the 2011 C++ standard,
 @code{201402L} for the 2014 C++ standard,
 @code{201703L} f

[PATCH v2] c++: Add support for -std=c++2b

2021-01-10 Thread Paul Fee via Gcc-patches
[PATCH v2] c++: Add support for -std=c++2b

Derived from the changes that added C++2a support in 2017.
https://gcc.gnu.org/g:026a79f70cf33f836ea5275eda72d4870a3041e5

No C++2b features are added here.
Use of -std=c++2b sets __cplusplus to 202100L.

$ g++ -std=c++2b -dM -E -x c++ - < /dev/null | grep cplusplus
#define __cplusplus 202100L

Changes since v1 (8th Jan 2021):
* As suggested by Jonathan Wakely:
  __cplusplus set to 202100L rather than 202101L.  Use of a non-existent date
  helps indicate this is not a true standard, yet is a value greater
than 202002L.
* As suggested by Jakub Jelinek:
  Fixed typos and formatting.
  Added C++23 support to dwarf2out.c, including missing C++20 support
in highest_c_language.
* Regarding suggestion by Marek Polacek to refer to C++23 rather than C++2b.
  Left the option as -std=c++2b for now.  It may be premature to assume the next
  version of the standard will be named C++23.  Use of c++2b also reinforces
  the experimental nature of GCC's C++23 implementation.


gcc/

Add support for -std=c++2b
* doc/cpp.texi (__cplusplus): Document value for -std=c++2b
or -std=gnu++2b.
* doc/invoke.texi: Document -std=c++2b and -std=gnu++2b.

gcc/c-family

Add support for -std=c++2b
* c-common.h (cxx_dialect): Add cxx2b as a dialect.
* c.opt: Add options for -std=c++2b and -std=gnu++2b.
* c-opts.c (set_std_cxx2b): New.
(c_common_handle_option): Set options when -std=c++2b is enabled.
(c_common_post_options): Adjust comments.
(set_std_cxx20): Likewise.
* dwarf2out.c (highest_c_language): Recognise C++20 and C++23.
(gen_compile_unit_die): Recognise C++23.

gcc/testsuite

Add support for -std=c++2b
* lib/target-supports.exp (check_effective_target_c++2a_only):
rename to check_effective_target_c++20_only.
(check_effective_target_c++2a): rename to check_effective_target_c++20.
(check_effective_target_c++20): Return 1
if check_effective_target_c++20_only or
if check_effective_target_c++2b.
(check_effective_target_c++20_down): New.
(check_effective_target_c++2a_only): New.
(check_effective_target_c++2a): New.
* g++.dg/cpp2b/cplusplus.C: New.

libcpp
Add support for -std=c++2b
* include/cpplib.h (c_lang): Add CXX2B and GNUCXX2B.
* init.c (lang_defaults): Add rows for CXX2B and GNUCXX2B.
(cpp_init_builtins): Set __cplusplus to 202100L for C++2b.
---
 gcc/c-family/c-common.h|4 ++-
 gcc/c-family/c-opts.c  |   29 ++--
 gcc/c-family/c.opt |8 ++
 gcc/doc/cpp.texi   |7 +++--
 gcc/doc/invoke.texi|   10 
 gcc/dwarf2out.c|7 +
 gcc/testsuite/g++.dg/cpp2b/cplusplus.C |4 +++
 gcc/testsuite/lib/target-supports.exp  |   39 +++--
 libcpp/include/cpplib.h|3 +-
 libcpp/init.c  |7 +
 10 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index a65c78f7240..f562cdebf4c 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -738,7 +738,9 @@ enum cxx_dialect {
   /* C++17 */
   cxx17,
   /* C++20 */
-  cxx20
+  cxx20,
+  /* C++2b (C++23?) */
+  cxx2b
 };

 /* The C++ dialect being used. C++98 is the default.  */
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 3cdf41bc6e2..15f120d475d 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -113,6 +113,7 @@ static void set_std_cxx11 (int);
 static void set_std_cxx14 (int);
 static void set_std_cxx17 (int);
 static void set_std_cxx20 (int);
+static void set_std_cxx2b (int);
 static void set_std_c89 (int, int);
 static void set_std_c99 (int);
 static void set_std_c11 (int);
@@ -649,6 +650,12 @@ c_common_handle_option (size_t scode, const char
*arg, HOST_WIDE_INT value,
 set_std_cxx20 (code == OPT_std_c__20 /* ISO */);
   break;

+case OPT_std_c__2b:
+case OPT_std_gnu__2b:
+  if (!preprocessing_asm_p)
+set_std_cxx2b (code == OPT_std_c__2b /* ISO */);
+  break;
+
 case OPT_std_c90:
 case OPT_std_iso9899_199409:
   if (!preprocessing_asm_p)
@@ -1019,7 +1026,7 @@ c_common_post_options (const char **pfilename)
 warn_narrowing = 1;

   /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
- for -std=c++{11,14,17,2a} default to -fno-ext-numeric-literals.  */
+ for -std=c++{11,14,17,20,2b} default to -fno-ext-numeric-literals.  */
   if (flag_iso && !global_options_set.x_flag_ext_numeric_literals)
 cpp_opts->ext_numeric_literals = 0;
 }
@@ -1763,7 +1770,7 @@ set_std_cxx20 (int iso)
   flag_no_gnu_keywords = iso;
   flag_no_nonansi_builtin = iso;
   flag_iso = iso;
-  /* C++17 includes the C11 standard library.  */
+  /* C++20 includes the C11 standard library.  */
   flag_isoc94 = 1;
   flag_isoc99 = 1;
   flag_isoc11 = 1;
@@ -1773,6 +1

Re: [PATCH] c++: Add support for -std=c++2b

2021-01-10 Thread Paul Fee via Gcc-patches
See "[PATCH v2] c++: Add support for -std=c++2b" for fixes.

On Fri, Jan 8, 2021 at 3:16 PM Marek Polacek  wrote:
>
> I think we should consider making this -std=c++23 right away this time,
> since we're on a three-year release schedule.  Up to Jason though.
>
> Marek
>


[PATCH] libstdc++: c++2b, implement WG21 P1679R3

2021-01-12 Thread Paul Fee via Gcc-patches
Add contains member function to basic_string_view and basic_string.

The new method is enabled for -std=gnu++20, gnu++2b and c++2b.  This allows
users to access the method as a GNU extension to C++20.  The conditional
test may be reduced to "__cplusplus > 202011L" once GCC has a c++2b switch.

libstdc++-v3/

Add contains member function to basic_string_view.
Likewise to basic_string_view, both with and without _GLIBCXX_USE_CXX11_ABI.
Enabled with -std=gnu++20, gnu++2b and c++2b.
* include/bits/basic_string.h (basic_string::contains): New.
* libstdc++-v3/include/std/string_view (basic_string_view::contains): New.
* testsuite/21_strings/basic_string/operations/contains/char/1.cc: New test.
* testsuite/21_strings/basic_string/operations/contains/wchar_t/1.cc:
New test.
* testsuite/21_strings/basic_string/operations/starts_with/char/1.cc:
Remove trailing whitespace
* testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc:
Remove trailing whitespace
* testsuite/21_strings/basic_string_view/operations/contains/char/1.cc:
New test.
* testsuite/21_strings/basic_string_view/operations/contains/wchar_t/1.cc:
New test.
---
 libstdc++-v3/include/bits/basic_string.h
   |   30 
 libstdc++-v3/include/std/string_view
   |   16 ++
 libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/char/1.cc
|   65 ++
 libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/wchar_t/1.cc
 |   65 ++
 libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char/1.cc
 |2
 
libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc
  |2
 
libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/char/1.cc
   |   51 +++
 
libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/wchar_t/1.cc
|   51 +++
 8 files changed, 280 insertions(+), 2 deletions(-)


diff --git a/libstdc++-v3/include/bits/basic_string.h
b/libstdc++-v3/include/bits/basic_string.h
index e272d332934..a569ecd8c08 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -3073,6 +3073,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   { return __sv_type(this->data(), this->size()).ends_with(__x); }
 #endif // C++20

+#if __cplusplus > 202011L || \
+  (__cplusplus == 202002L && !defined __STRICT_ANSI__)
+  bool
+  contains(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(const _CharT* __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+#endif // C++23
+
   // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
   template friend class basic_stringbuf;
 };
@@ -5998,6 +6013,21 @@ _GLIBCXX_END_NAMESPACE_CXX11
   { return __sv_type(this->data(), this->size()).ends_with(__x); }
 #endif // C++20

+#if __cplusplus > 202011L || \
+  (__cplusplus == 202002L && !defined __STRICT_ANSI__)
+  bool
+  contains(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(const _CharT* __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+#endif // C++23
+
 # ifdef _GLIBCXX_TM_TS_INTERNAL
   friend void
   ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s,
diff --git a/libstdc++-v3/include/std/string_view
b/libstdc++-v3/include/std/string_view
index e33e1bc4b79..2f47ef6ed12 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -352,6 +352,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { return this->ends_with(basic_string_view(__x)); }
 #endif // C++20

+#if __cplusplus > 202011L || \
+  (__cplusplus == 202002L && !defined __STRICT_ANSI__)
+#define __cpp_lib_string_contains 202011L
+  constexpr bool
+  contains(basic_string_view __x) const noexcept
+  { return this->find(__x) != npos; }
+
+  constexpr bool
+  contains(_CharT __x) const noexcept
+  { return this->find(__x) != npos; }
+
+  constexpr bool
+  contains(const _CharT* __x) const noexcept
+  { return this->find(__x) != npos; }
+#endif // C++23
+
   // [string.view.find], searching

   constexpr size_type
diff --git 
a/libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/char/1.cc
b/libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/char/1.cc
new file mode 100644
index 000..5d81dcee0ad
--- /dev/null
+++ 
b/libstdc++-v3/testsuite/21_strings/basic_string/operations/contains

[PATCH v2] libstdc++: C++23, implement WG21 P1679R3

2021-01-14 Thread Paul Fee via Gcc-patches
Add contains member function to basic_string_view and basic_string.

The new method is enabled for -std=gnu++20, gnu++2b and c++2b.  This allows
users to access the method as a GNU extension to C++20.  The conditional
test may be reduced to "__cplusplus > 202011L" once GCC has a c++2b switch.

Changes since v1 (13th Jan 2021)
* New:
  Test __cplusplus >= 202011L, rather than __cplusplus > 202011L.

* As suggested by Jonathan Wakely:
  Adjust formatting.
  Test feature-test macro is defined by  and .
  Correct copyright dates on new files.
  Fix comment typo.

libstdc++-v3/

Add contains member function to basic_string_view.
Likewise to basic_string_view, both with and without _GLIBCXX_USE_CXX11_ABI.
Enabled with -std=gnu++20, gnu++2b and c++2b.
* include/bits/basic_string.h (basic_string::contains): New.
* libstdc++-v3/include/std/string_view (basic_string_view::contains): New.
* testsuite/21_strings/basic_string/operations/contains/char/1.cc: New test.
* testsuite/21_strings/basic_string/operations/contains/wchar_t/1.cc:
New test.
* testsuite/21_strings/basic_string_view/operations/contains/char/1.cc:
New test.
* testsuite/21_strings/basic_string_view/operations/contains/wchar_t/1.cc:
New test.
---
 libstdc++-v3/include/bits/basic_string.h
   |   30 
 libstdc++-v3/include/std/string_view
   |   16 ++
 libstdc++-v3/include/std/version
   |9 +
 libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/char/1.cc
|   65 ++
 libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/wchar_t/1.cc
 |   65 ++
 libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char/1.cc
 |2
 
libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t/1.cc
  |2
 
libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/char/1.cc
   |   57 
 
libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/char/2.cc
   |   27 
 
libstdc++-v3/testsuite/21_strings/basic_string_view/operations/contains/wchar_t/1.cc
|   51 +++
 10 files changed, 320 insertions(+), 4 deletions(-)


diff --git a/libstdc++-v3/include/bits/basic_string.h
b/libstdc++-v3/include/bits/basic_string.h
index e272d332934..ec0abca2a5d 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -3073,6 +3073,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
   { return __sv_type(this->data(), this->size()).ends_with(__x); }
 #endif // C++20

+#if __cplusplus >= 202011L \
+  || (__cplusplus == 202002L && !defined __STRICT_ANSI__)
+  bool
+  contains(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(const _CharT* __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+#endif // C++23
+
   // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
   template friend class basic_stringbuf;
 };
@@ -5998,6 +6013,21 @@ _GLIBCXX_END_NAMESPACE_CXX11
   { return __sv_type(this->data(), this->size()).ends_with(__x); }
 #endif // C++20

+#if __cplusplus >= 202011L \
+  || (__cplusplus == 202002L && !defined __STRICT_ANSI__)
+  bool
+  contains(basic_string_view<_CharT, _Traits> __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(_CharT __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+
+  bool
+  contains(const _CharT* __x) const noexcept
+  { return __sv_type(this->data(), this->size()).contains(__x); }
+#endif // C++23
+
 # ifdef _GLIBCXX_TM_TS_INTERNAL
   friend void
   ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s,
diff --git a/libstdc++-v3/include/std/string_view
b/libstdc++-v3/include/std/string_view
index e33e1bc4b79..6a6863cf189 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -352,6 +352,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   { return this->ends_with(basic_string_view(__x)); }
 #endif // C++20

+#if __cplusplus >= 202011L \
+  || (__cplusplus == 202002L && !defined __STRICT_ANSI__)
+#define __cpp_lib_string_contains 202011L
+  constexpr bool
+  contains(basic_string_view __x) const noexcept
+  { return this->find(__x) != npos; }
+
+  constexpr bool
+  contains(_CharT __x) const noexcept
+  { return this->find(__x) != npos; }
+
+  constexpr bool
+  contains(const _CharT* __x) const noexcept
+  { return this->find(__x) != npos; }
+#endif // C++23
+
   // [string.view.find], searching

   constexpr size_type
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version

Re: [PATCH] libstdc++: c++2b, implement WG21 P1679R3

2021-01-14 Thread Paul Fee via Gcc-patches
On Thu, Jan 14, 2021 at 5:06 PM Jonathan Wakely  wrote:
>
> On 13/01/21 01:21 +, Paul Fee via Libstdc++ wrote:
> >Add contains member function to basic_string_view and basic_string.
> >
> >The new method is enabled for -std=gnu++20, gnu++2b and c++2b.  This allows
> >users to access the method as a GNU extension to C++20.  The conditional
> >test may be reduced to "__cplusplus > 202011L" once GCC has a c++2b switch.
>
> Thanks for the patch.
>
> A few comments below.
>

Thanks for the feedback, see "[PATCH v2] libstdc++: C++23, implement
WG21 P1679R3" for fixes.