public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: Jason Merrill <jason@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [pushed] c++: __integer_pack with class argument [PR111357]
Date: Tue, 12 Sep 2023 19:49:46 +0200	[thread overview]
Message-ID: <ZQCkuk6J0KOqu33P@tucnak> (raw)
In-Reply-To: <ZQChM+3JDOjGhECg@redhat.com>

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


  reply	other threads:[~2023-09-12 17:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 17:27 Jason Merrill
2023-09-12 17:34 ` Marek Polacek
2023-09-12 17:49   ` Jakub Jelinek [this message]
2023-09-22 14:35     ` [pushed] c++ __integer_pack conversion again [PR111357] Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZQCkuk6J0KOqu33P@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).