* [pushed] c++: __integer_pack with class argument [PR111357]
@ 2023-09-12 17:27 Jason Merrill
2023-09-12 17:34 ` Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2023-09-12 17:27 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
The argument might not already be an integer.
PR c++/111357
gcc/cp/ChangeLog:
* pt.cc (expand_integer_pack): Convert argument to int.
gcc/testsuite/ChangeLog:
* g++.dg/ext/integer-pack7.C: New test.
---
gcc/cp/pt.cc | 2 ++
gcc/testsuite/g++.dg/ext/integer-pack7.C | 38 ++++++++++++++++++++++++
2 files changed, 40 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/ext/integer-pack7.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 838179d5fe3..b583c11eb99 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -3793,6 +3793,8 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain,
}
else
{
+ hi = perform_implicit_conversion_flags (integer_type_node, hi, complain,
+ LOOKUP_IMPLICIT);
hi = instantiate_non_dependent_expr (hi, complain);
hi = cxx_constant_value (hi, complain);
int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1;
diff --git a/gcc/testsuite/g++.dg/ext/integer-pack7.C b/gcc/testsuite/g++.dg/ext/integer-pack7.C
new file mode 100644
index 00000000000..95b1195bef4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/integer-pack7.C
@@ -0,0 +1,38 @@
+// PR c++/111357
+// { dg-do compile { target c++11 } }
+
+namespace std {
+ template<typename _Tp, _Tp... _Idx>
+ struct integer_sequence
+ { };
+
+ template<typename _Tp, _Tp _Num>
+ using make_integer_sequence
+ = integer_sequence<_Tp, __integer_pack(_Num)...>;
+}
+
+using std::integer_sequence;
+using std::make_integer_sequence;
+
+template<int... V>
+void g(integer_sequence<int,V...>)
+{}
+
+template<typename ...T>
+struct c1
+{
+ static constexpr int value = 1;
+ constexpr operator int() { return value; }
+};
+template<typename T>
+struct R
+{
+ using S = make_integer_sequence<int,c1<T>{}>;
+
+ R() noexcept(noexcept(g(S())))
+ {}
+};
+int main()
+{
+ R<int>();
+}
base-commit: ea5abbb263315e558c876b50c9371b90ddd5e028
--
2.39.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pushed] c++: __integer_pack with class argument [PR111357]
2023-09-12 17:27 [pushed] c++: __integer_pack with class argument [PR111357] Jason Merrill
@ 2023-09-12 17:34 ` Marek Polacek
2023-09-12 17:49 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2023-09-12 17:34 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Tue, Sep 12, 2023 at 01:27:44PM -0400, Jason Merrill via Gcc-patches wrote:
> Tested x86_64-pc-linux-gnu, applying to trunk.
>
> -- 8< --
>
> The argument might not already be an integer.
>
> PR c++/111357
>
> gcc/cp/ChangeLog:
>
> * pt.cc (expand_integer_pack): Convert argument to int.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/integer-pack7.C: New test.
> ---
> gcc/cp/pt.cc | 2 ++
> gcc/testsuite/g++.dg/ext/integer-pack7.C | 38 ++++++++++++++++++++++++
> 2 files changed, 40 insertions(+)
> create mode 100644 gcc/testsuite/g++.dg/ext/integer-pack7.C
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 838179d5fe3..b583c11eb99 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -3793,6 +3793,8 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain,
> }
> else
> {
> + hi = perform_implicit_conversion_flags (integer_type_node, hi, complain,
> + LOOKUP_IMPLICIT);
FWIW, we have perform_implicit_conversion for this.
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pushed] c++: __integer_pack with class argument [PR111357]
2023-09-12 17:34 ` Marek Polacek
@ 2023-09-12 17:49 ` Jakub Jelinek
2023-09-22 14:35 ` [pushed] c++ __integer_pack conversion again [PR111357] Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2023-09-12 17:49 UTC (permalink / raw)
To: Marek Polacek; +Cc: Jason Merrill, gcc-patches
On Tue, Sep 12, 2023 at 01:34:43PM -0400, Marek Polacek via Gcc-patches wrote:
> On Tue, Sep 12, 2023 at 01:27:44PM -0400, Jason Merrill via Gcc-patches wrote:
> > Tested x86_64-pc-linux-gnu, applying to trunk.
> >
> > -- 8< --
> >
> > The argument might not already be an integer.
> >
> > PR c++/111357
> >
> > gcc/cp/ChangeLog:
> >
> > * pt.cc (expand_integer_pack): Convert argument to int.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * g++.dg/ext/integer-pack7.C: New test.
> > ---
> > gcc/cp/pt.cc | 2 ++
> > gcc/testsuite/g++.dg/ext/integer-pack7.C | 38 ++++++++++++++++++++++++
> > 2 files changed, 40 insertions(+)
> > create mode 100644 gcc/testsuite/g++.dg/ext/integer-pack7.C
> >
> > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> > index 838179d5fe3..b583c11eb99 100644
> > --- a/gcc/cp/pt.cc
> > +++ b/gcc/cp/pt.cc
> > @@ -3793,6 +3793,8 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain,
> > }
> > else
> > {
> > + hi = perform_implicit_conversion_flags (integer_type_node, hi, complain,
> > + LOOKUP_IMPLICIT);
>
> FWIW, we have perform_implicit_conversion for this.
Is it correct to convert exactly to integer_type_node though?
Consider
#include <utility>
using std::integer_sequence;
using std::make_integer_sequence;
template<long... V>
void g(integer_sequence<long,V...>)
{}
template<typename ...T>
struct c1
{
static constexpr int value = 1;
constexpr operator int() { return value; }
constexpr operator long() { return value + 1; }
};
template<typename T>
struct R
{
using S = make_integer_sequence<long,c1<T>{}>;
R() noexcept(noexcept(g(S())))
{}
};
int main()
{
R<int>();
}
Shouldn't that invoke c1<T>{}.operator long() rather than operator int()?
I thought the conversion was supposed to be done a few lines earlier,
instead of doing
CALL_EXPR_ARG (call, 0) = hi;
do
CALL_EXPR_ARG (call, 0)
= perform_implicit_conversion_flags (TREE_TYPE (ohi), hi,
complain, LOOKUP_IMPLICIT);
or tsubst that TREE_TYPE (ohi) as well? I.e. convert to type of the
template parameter.
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pushed] c++ __integer_pack conversion again [PR111357]
2023-09-12 17:49 ` Jakub Jelinek
@ 2023-09-22 14:35 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2023-09-22 14:35 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
As Jakub pointed out, the real problem here is that in a partial
substitution we're forgetting the conversion to the type of the non-type
template argument, because maybe_convert_nontype_argument doesn't do
anything with value-dependent arguments. I'm experimenting with changing
that, but in the meantime we can work around it here.
PR c++/111357
gcc/cp/ChangeLog:
* pt.cc (expand_integer_pack): Use IMPLICIT_CONV_EXPR.
---
gcc/cp/pt.cc | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ea5379098a5..73ac1cb597c 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -3769,6 +3769,13 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain,
{
if (hi != ohi)
{
+ /* Work around maybe_convert_nontype_argument not doing this for
+ dependent arguments. Don't use IMPLICIT_CONV_EXPR_NONTYPE_ARG
+ because that will make tsubst_copy_and_build ignore it. */
+ tree type = tsubst (TREE_TYPE (ohi), args, complain, in_decl);
+ if (!TREE_TYPE (hi) || !same_type_p (type, TREE_TYPE (hi)))
+ hi = build1 (IMPLICIT_CONV_EXPR, type, hi);
+
call = copy_node (call);
CALL_EXPR_ARG (call, 0) = hi;
}
@@ -3779,8 +3786,6 @@ expand_integer_pack (tree call, tree args, tsubst_flags_t complain,
}
else
{
- hi = perform_implicit_conversion_flags (integer_type_node, hi, complain,
- LOOKUP_IMPLICIT);
hi = instantiate_non_dependent_expr (hi, complain);
hi = cxx_constant_value (hi, complain);
int len = valid_constant_size_p (hi) ? tree_to_shwi (hi) : -1;
base-commit: 22cda0ca5fb406f22925bbf51ab152a958e3319d
--
2.39.3
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-22 14:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 17:27 [pushed] c++: __integer_pack with class argument [PR111357] Jason Merrill
2023-09-12 17:34 ` Marek Polacek
2023-09-12 17:49 ` Jakub Jelinek
2023-09-22 14:35 ` [pushed] c++ __integer_pack conversion again [PR111357] Jason Merrill
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).