* [PATCH 1/2] c++: implement __add_const built-in trait
@ 2023-03-21 11:10 Ken Matsui
2023-03-21 11:10 ` [PATCH 2/2] libstdc++: use new built-in trait __add_const Ken Matsui
2023-03-21 11:26 ` [PATCH 1/2] c++: implement __add_const built-in trait Jonathan Wakely
0 siblings, 2 replies; 7+ messages in thread
From: Ken Matsui @ 2023-03-21 11:10 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, ppalka, Ken Matsui
This patch implements built-in trait for std::add_const.
gcc/cp/ChangeLog:
* cp-trait.def: Define __add_const.
* semantics.cc (finish_trait_type): Handle CPTK_ADD_CONST.
gcc/testsuite/ChangeLog:
* g++.dg/ext/has-builtin-1.C: Test existence of __add_const.
* g++.dg/ext/add_const.C: New test.
---
gcc/cp/cp-trait.def | 1 +
gcc/cp/semantics.cc | 6 ++++
gcc/testsuite/g++.dg/ext/add_const.C | 39 ++++++++++++++++++++++++
gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++
4 files changed, 49 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/ext/add_const.C
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index bac593c0094..e362c448c84 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -91,6 +91,7 @@ DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1)
+DEFTRAIT_TYPE (ADD_CONST, "__add_const", 1)
/* These traits yield a type pack, not a type, and are represented by
cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE tree. */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 87c2e8a7111..14e27a71a55 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12273,6 +12273,12 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2)
if (TYPE_REF_P (type1))
type1 = TREE_TYPE (type1);
return cv_unqualified (type1);
+ case CPTK_ADD_CONST:
+ if (TYPE_REF_P (type1) || TYPE_PTRFN_P (type1))
+ return type1;
+ return cp_build_qualified_type (type1,
+ cp_type_quals (type1) |
+ TYPE_QUAL_CONST);
#define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
case CPTK_##CODE:
diff --git a/gcc/testsuite/g++.dg/ext/add_const.C b/gcc/testsuite/g++.dg/ext/add_const.C
new file mode 100644
index 00000000000..1c8618a8b00
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/add_const.C
@@ -0,0 +1,39 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+SA(__is_same(__add_const(void), const void));
+SA(__is_same(__add_const(int), const int));
+
+SA(__is_same(__add_const(const int), const int));
+SA(__is_same(__add_const(volatile int), const volatile int));
+SA(__is_same(__add_const(const volatile int), const volatile int));
+
+SA(__is_same(__add_const(int*), int* const));
+SA(__is_same(__add_const(int* const), int* const));
+SA(__is_same(__add_const(int* volatile), int* const volatile));
+SA(__is_same(__add_const(int* const volatile), int* const volatile));
+
+SA(__is_same(__add_const(const int*), const int* const));
+SA(__is_same(__add_const(volatile int*), volatile int* const));
+SA(__is_same(__add_const(const volatile int*), const volatile int* const));
+
+SA(__is_same(__add_const(int&), int&));
+SA(__is_same(__add_const(const int&), const int&));
+SA(__is_same(__add_const(volatile int&), volatile int&));
+SA(__is_same(__add_const(const volatile int&), const volatile int&));
+
+SA(__is_same(__add_const(int&&), int&&));
+SA(__is_same(__add_const(const int&&), const int&&));
+SA(__is_same(__add_const(volatile int&&), volatile int&&));
+SA(__is_same(__add_const(const volatile int&&), const volatile int&&));
+
+SA(__is_same(__add_const(int[3]), const int[3]));
+SA(__is_same(__add_const(const int[3]), const int[3]));
+SA(__is_same(__add_const(volatile int[3]), const volatile int[3]));
+SA(__is_same(__add_const(const volatile int[3]), const volatile int[3]));
+
+SA(__is_same(__add_const(int(int)), int(int)));
+SA(__is_same(__add_const(int(*const)(int)), int(*const)(int)));
+SA(__is_same(__add_const(int(*volatile)(int)), int(*volatile)(int)));
+SA(__is_same(__add_const(int(*const volatile)(int)), int(*const volatile)(int)));
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index f343e153e56..dd331ebbc9a 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -146,3 +146,6 @@
#if !__has_builtin (__remove_cvref)
# error "__has_builtin (__remove_cvref) failed"
#endif
+#if !__has_builtin (__add_const)
+# error "__has_builtin (__add_const) failed"
+#endif
--
2.40.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] libstdc++: use new built-in trait __add_const
2023-03-21 11:10 [PATCH 1/2] c++: implement __add_const built-in trait Ken Matsui
@ 2023-03-21 11:10 ` Ken Matsui
2023-03-21 11:20 ` Marc Glisse
2023-03-21 11:26 ` [PATCH 1/2] c++: implement __add_const built-in trait Jonathan Wakely
1 sibling, 1 reply; 7+ messages in thread
From: Ken Matsui @ 2023-03-21 11:10 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, ppalka, Ken Matsui
This patch lets libstdc++ use new built-in trait __add_const.
libstdc++-v3/ChangeLog:
* include/std/type_traits (add_const): Use __add_const built-in trait.
---
libstdc++-v3/include/std/type_traits | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 2bd607a8b8f..1ac75a928c3 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1560,9 +1560,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
/// add_const
+#if __has_builtin(__add_const)
+ template<typename _Tp>
+ struct add_const
+ { using type = __add_const(_Tp); };
+#else
template<typename _Tp>
struct add_const
{ using type = _Tp const; };
+#endif
/// add_volatile
template<typename _Tp>
--
2.40.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] libstdc++: use new built-in trait __add_const
2023-03-21 11:10 ` [PATCH 2/2] libstdc++: use new built-in trait __add_const Ken Matsui
@ 2023-03-21 11:20 ` Marc Glisse
2023-03-21 11:24 ` Jonathan Wakely
0 siblings, 1 reply; 7+ messages in thread
From: Marc Glisse @ 2023-03-21 11:20 UTC (permalink / raw)
To: Ken Matsui; +Cc: gcc-patches, libstdc++, ppalka
On Tue, 21 Mar 2023, Ken Matsui via Libstdc++ wrote:
> /// add_const
> +#if __has_builtin(__add_const)
> + template<typename _Tp>
> + struct add_const
> + { using type = __add_const(_Tp); };
> +#else
> template<typename _Tp>
> struct add_const
> { using type = _Tp const; };
> +#endif
Is that really better? You asked elsewhere if you should measure for each
patch, and I think that at least for such a trivial case, you need to
demonstrate that there is a point. The drawbacks are obvious: more code in
libstdc++, non-standard, and more builtins in the compiler.
Using builtins makes more sense for complicated traits where you can save
several instantiations. Now that you have done a couple simple cases to
see how it works, I think you should concentrate on the more complicated
cases.
--
Marc Glisse
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] libstdc++: use new built-in trait __add_const
2023-03-21 11:20 ` Marc Glisse
@ 2023-03-21 11:24 ` Jonathan Wakely
2023-03-21 11:37 ` Ken Matsui
0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2023-03-21 11:24 UTC (permalink / raw)
To: libstdc++; +Cc: Ken Matsui, Marc Glisse, gcc-patches, ppalka
[-- Attachment #1: Type: text/plain, Size: 1329 bytes --]
On Tue, 21 Mar 2023 at 11:21, Marc Glisse via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:
> On Tue, 21 Mar 2023, Ken Matsui via Libstdc++ wrote:
>
> > /// add_const
> > +#if __has_builtin(__add_const)
> > + template<typename _Tp>
> > + struct add_const
> > + { using type = __add_const(_Tp); };
> > +#else
> > template<typename _Tp>
> > struct add_const
> > { using type = _Tp const; };
> > +#endif
>
> Is that really better? You asked elsewhere if you should measure for each
> patch, and I think that at least for such a trivial case, you need to
> demonstrate that there is a point. The drawbacks are obvious: more code in
> libstdc++, non-standard, and more builtins in the compiler.
>
Right, this one isn't even getting rid of any partial specializations, but
it is giving the preprocessor more work to do.
Adding the extra built-ins to the compiler makes the compiler (very
slightly) bigger and slower, so a real benchmark would require comparing an
unpatched gcc (without the new built-in) to a patched gcc and patched
libstdc++ sources.
>
> Using builtins makes more sense for complicated traits where you can save
> several instantiations. Now that you have done a couple simple cases to
> see how it works, I think you should concentrate on the more complicated
> cases.
>
> --
> Marc Glisse
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] c++: implement __add_const built-in trait
2023-03-21 11:10 [PATCH 1/2] c++: implement __add_const built-in trait Ken Matsui
2023-03-21 11:10 ` [PATCH 2/2] libstdc++: use new built-in trait __add_const Ken Matsui
@ 2023-03-21 11:26 ` Jonathan Wakely
2023-03-21 11:29 ` Jonathan Wakely
1 sibling, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2023-03-21 11:26 UTC (permalink / raw)
To: Ken Matsui; +Cc: gcc-patches, libstdc++, ppalka
[-- Attachment #1: Type: text/plain, Size: 4631 bytes --]
On Tue, 21 Mar 2023 at 11:12, Ken Matsui via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:
> This patch implements built-in trait for std::add_const.
>
> gcc/cp/ChangeLog:
>
> * cp-trait.def: Define __add_const.
> * semantics.cc (finish_trait_type): Handle CPTK_ADD_CONST.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/has-builtin-1.C: Test existence of __add_const.
> * g++.dg/ext/add_const.C: New test.
> ---
> gcc/cp/cp-trait.def | 1 +
> gcc/cp/semantics.cc | 6 ++++
> gcc/testsuite/g++.dg/ext/add_const.C | 39 ++++++++++++++++++++++++
> gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++
> 4 files changed, 49 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/ext/add_const.C
>
> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
> index bac593c0094..e362c448c84 100644
> --- a/gcc/cp/cp-trait.def
> +++ b/gcc/cp/cp-trait.def
> @@ -91,6 +91,7 @@ DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
> DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
> DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
> DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1)
> +DEFTRAIT_TYPE (ADD_CONST, "__add_const", 1)
>
> /* These traits yield a type pack, not a type, and are represented by
> cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE tree.
> */
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 87c2e8a7111..14e27a71a55 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12273,6 +12273,12 @@ finish_trait_type (cp_trait_kind kind, tree
> type1, tree type2)
> if (TYPE_REF_P (type1))
> type1 = TREE_TYPE (type1);
> return cv_unqualified (type1);
> + case CPTK_ADD_CONST:
> + if (TYPE_REF_P (type1) || TYPE_PTRFN_P (type1))
> + return type1;
> + return cp_build_qualified_type (type1,
> + cp_type_quals (type1) |
> + TYPE_QUAL_CONST);
>
> #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
> case CPTK_##CODE:
> diff --git a/gcc/testsuite/g++.dg/ext/add_const.C
> b/gcc/testsuite/g++.dg/ext/add_const.C
> new file mode 100644
> index 00000000000..1c8618a8b00
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/add_const.C
> @@ -0,0 +1,39 @@
> +// { dg-do compile { target c++11 } }
> +
> +#define SA(X) static_assert((X),#X)
> +
> +SA(__is_same(__add_const(void), const void));
> +SA(__is_same(__add_const(int), const int));
> +
> +SA(__is_same(__add_const(const int), const int));
> +SA(__is_same(__add_const(volatile int), const volatile int));
> +SA(__is_same(__add_const(const volatile int), const volatile int));
> +
> +SA(__is_same(__add_const(int*), int* const));
> +SA(__is_same(__add_const(int* const), int* const));
> +SA(__is_same(__add_const(int* volatile), int* const volatile));
> +SA(__is_same(__add_const(int* const volatile), int* const volatile));
> +
> +SA(__is_same(__add_const(const int*), const int* const));
> +SA(__is_same(__add_const(volatile int*), volatile int* const));
> +SA(__is_same(__add_const(const volatile int*), const volatile int*
> const));
> +
> +SA(__is_same(__add_const(int&), int&));
> +SA(__is_same(__add_const(const int&), const int&));
> +SA(__is_same(__add_const(volatile int&), volatile int&));
> +SA(__is_same(__add_const(const volatile int&), const volatile int&));
> +
> +SA(__is_same(__add_const(int&&), int&&));
> +SA(__is_same(__add_const(const int&&), const int&&));
> +SA(__is_same(__add_const(volatile int&&), volatile int&&));
> +SA(__is_same(__add_const(const volatile int&&), const volatile int&&));
> +
> +SA(__is_same(__add_const(int[3]), const int[3]));
> +SA(__is_same(__add_const(const int[3]), const int[3]));
> +SA(__is_same(__add_const(volatile int[3]), const volatile int[3]));
> +SA(__is_same(__add_const(const volatile int[3]), const volatile int[3]));
> +
> +SA(__is_same(__add_const(int(int)), int(int)));
> +SA(__is_same(__add_const(int(*const)(int)), int(*const)(int)));
> +SA(__is_same(__add_const(int(*volatile)(int)), int(*volatile)(int)));
>
This looks wrong.
> +SA(__is_same(__add_const(int(*const volatile)(int)), int(*const
> volatile)(int)));
> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> index f343e153e56..dd331ebbc9a 100644
> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> @@ -146,3 +146,6 @@
> #if !__has_builtin (__remove_cvref)
> # error "__has_builtin (__remove_cvref) failed"
> #endif
> +#if !__has_builtin (__add_const)
> +# error "__has_builtin (__add_const) failed"
> +#endif
> --
> 2.40.0
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] c++: implement __add_const built-in trait
2023-03-21 11:26 ` [PATCH 1/2] c++: implement __add_const built-in trait Jonathan Wakely
@ 2023-03-21 11:29 ` Jonathan Wakely
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2023-03-21 11:29 UTC (permalink / raw)
To: Ken Matsui; +Cc: gcc-patches, libstdc++, ppalka
[-- Attachment #1: Type: text/plain, Size: 4911 bytes --]
On Tue, 21 Mar 2023 at 11:26, Jonathan Wakely wrote:
>
>
> On Tue, 21 Mar 2023 at 11:12, Ken Matsui via Libstdc++ <
> libstdc++@gcc.gnu.org> wrote:
>
>> This patch implements built-in trait for std::add_const.
>>
>> gcc/cp/ChangeLog:
>>
>> * cp-trait.def: Define __add_const.
>> * semantics.cc (finish_trait_type): Handle CPTK_ADD_CONST.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * g++.dg/ext/has-builtin-1.C: Test existence of __add_const.
>> * g++.dg/ext/add_const.C: New test.
>> ---
>> gcc/cp/cp-trait.def | 1 +
>> gcc/cp/semantics.cc | 6 ++++
>> gcc/testsuite/g++.dg/ext/add_const.C | 39 ++++++++++++++++++++++++
>> gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++
>> 4 files changed, 49 insertions(+)
>> create mode 100644 gcc/testsuite/g++.dg/ext/add_const.C
>>
>> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
>> index bac593c0094..e362c448c84 100644
>> --- a/gcc/cp/cp-trait.def
>> +++ b/gcc/cp/cp-trait.def
>> @@ -91,6 +91,7 @@ DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
>> DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
>> DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
>> DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1)
>> +DEFTRAIT_TYPE (ADD_CONST, "__add_const", 1)
>>
>> /* These traits yield a type pack, not a type, and are represented by
>> cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE
>> tree. */
>> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
>> index 87c2e8a7111..14e27a71a55 100644
>> --- a/gcc/cp/semantics.cc
>> +++ b/gcc/cp/semantics.cc
>> @@ -12273,6 +12273,12 @@ finish_trait_type (cp_trait_kind kind, tree
>> type1, tree type2)
>> if (TYPE_REF_P (type1))
>> type1 = TREE_TYPE (type1);
>> return cv_unqualified (type1);
>> + case CPTK_ADD_CONST:
>> + if (TYPE_REF_P (type1) || TYPE_PTRFN_P (type1))
>> + return type1;
>> + return cp_build_qualified_type (type1,
>> + cp_type_quals (type1) |
>> + TYPE_QUAL_CONST);
>>
>> #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
>> case CPTK_##CODE:
>> diff --git a/gcc/testsuite/g++.dg/ext/add_const.C
>> b/gcc/testsuite/g++.dg/ext/add_const.C
>> new file mode 100644
>> index 00000000000..1c8618a8b00
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/ext/add_const.C
>> @@ -0,0 +1,39 @@
>> +// { dg-do compile { target c++11 } }
>> +
>> +#define SA(X) static_assert((X),#X)
>> +
>> +SA(__is_same(__add_const(void), const void));
>> +SA(__is_same(__add_const(int), const int));
>> +
>> +SA(__is_same(__add_const(const int), const int));
>> +SA(__is_same(__add_const(volatile int), const volatile int));
>> +SA(__is_same(__add_const(const volatile int), const volatile int));
>> +
>> +SA(__is_same(__add_const(int*), int* const));
>> +SA(__is_same(__add_const(int* const), int* const));
>> +SA(__is_same(__add_const(int* volatile), int* const volatile));
>> +SA(__is_same(__add_const(int* const volatile), int* const volatile));
>> +
>> +SA(__is_same(__add_const(const int*), const int* const));
>> +SA(__is_same(__add_const(volatile int*), volatile int* const));
>> +SA(__is_same(__add_const(const volatile int*), const volatile int*
>> const));
>> +
>> +SA(__is_same(__add_const(int&), int&));
>> +SA(__is_same(__add_const(const int&), const int&));
>> +SA(__is_same(__add_const(volatile int&), volatile int&));
>> +SA(__is_same(__add_const(const volatile int&), const volatile int&));
>> +
>> +SA(__is_same(__add_const(int&&), int&&));
>> +SA(__is_same(__add_const(const int&&), const int&&));
>> +SA(__is_same(__add_const(volatile int&&), volatile int&&));
>> +SA(__is_same(__add_const(const volatile int&&), const volatile int&&));
>> +
>> +SA(__is_same(__add_const(int[3]), const int[3]));
>> +SA(__is_same(__add_const(const int[3]), const int[3]));
>> +SA(__is_same(__add_const(volatile int[3]), const volatile int[3]));
>> +SA(__is_same(__add_const(const volatile int[3]), const volatile int[3]));
>> +
>> +SA(__is_same(__add_const(int(int)), int(int)));
>> +SA(__is_same(__add_const(int(*const)(int)), int(*const)(int)));
>> +SA(__is_same(__add_const(int(*volatile)(int)), int(*volatile)(int)));
>>
>
> This looks wrong.
>
It might be useful to test pointer-to-member types too. And for
completeness, a class type.
>
>> +SA(__is_same(__add_const(int(*const volatile)(int)), int(*const
>> volatile)(int)));
>> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> index f343e153e56..dd331ebbc9a 100644
>> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> @@ -146,3 +146,6 @@
>> #if !__has_builtin (__remove_cvref)
>> # error "__has_builtin (__remove_cvref) failed"
>> #endif
>> +#if !__has_builtin (__add_const)
>> +# error "__has_builtin (__add_const) failed"
>> +#endif
>> --
>> 2.40.0
>>
>>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] libstdc++: use new built-in trait __add_const
2023-03-21 11:24 ` Jonathan Wakely
@ 2023-03-21 11:37 ` Ken Matsui
0 siblings, 0 replies; 7+ messages in thread
From: Ken Matsui @ 2023-03-21 11:37 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, Marc Glisse, gcc-patches, ppalka
[-- Attachment #1: Type: text/plain, Size: 1895 bytes --]
Thank you for your information. Although it matches my intuition, I sent
this patch because I was unsure my intuition was correct. As Jonathan
pointed out, there appear to be several implementation errors. The
benchmark result for this trait is kind of trivial, so I will implement the
other traits I want to implement and then come back here.
Thank you all for your help.
On Tue, Mar 21, 2023 at 4:25 AM Jonathan Wakely <jwakely@redhat.com> wrote:
>
>
> On Tue, 21 Mar 2023 at 11:21, Marc Glisse via Libstdc++ <
> libstdc++@gcc.gnu.org> wrote:
>
>> On Tue, 21 Mar 2023, Ken Matsui via Libstdc++ wrote:
>>
>> > /// add_const
>> > +#if __has_builtin(__add_const)
>> > + template<typename _Tp>
>> > + struct add_const
>> > + { using type = __add_const(_Tp); };
>> > +#else
>> > template<typename _Tp>
>> > struct add_const
>> > { using type = _Tp const; };
>> > +#endif
>>
>> Is that really better? You asked elsewhere if you should measure for each
>> patch, and I think that at least for such a trivial case, you need to
>> demonstrate that there is a point. The drawbacks are obvious: more code
>> in
>> libstdc++, non-standard, and more builtins in the compiler.
>>
>
> Right, this one isn't even getting rid of any partial specializations, but
> it is giving the preprocessor more work to do.
>
> Adding the extra built-ins to the compiler makes the compiler (very
> slightly) bigger and slower, so a real benchmark would require comparing an
> unpatched gcc (without the new built-in) to a patched gcc and patched
> libstdc++ sources.
>
>
>
>>
>> Using builtins makes more sense for complicated traits where you can save
>> several instantiations. Now that you have done a couple simple cases to
>> see how it works, I think you should concentrate on the more complicated
>> cases.
>>
>> --
>> Marc Glisse
>>
>>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-03-21 11:37 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21 11:10 [PATCH 1/2] c++: implement __add_const built-in trait Ken Matsui
2023-03-21 11:10 ` [PATCH 2/2] libstdc++: use new built-in trait __add_const Ken Matsui
2023-03-21 11:20 ` Marc Glisse
2023-03-21 11:24 ` Jonathan Wakely
2023-03-21 11:37 ` Ken Matsui
2023-03-21 11:26 ` [PATCH 1/2] c++: implement __add_const built-in trait Jonathan Wakely
2023-03-21 11:29 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).