public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nick Huang <nickhuang99@gmail.com>
To: Gcc-patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: [PATCH] c++: fix cases of core1001/1322 by not dropping cv-qualifier of function parameter of type of typename or decltype[PR101402, PR102033, PR102034, PR102039, PR102
Date: Sun, 3 Oct 2021 07:14:45 -0400	[thread overview]
Message-ID: <CAP6LXBt8JZoxjzuYMjO_K_QbdDKyP-FuxeboAC_MgfvxjyihzA@mail.gmail.com> (raw)

Hi Jason,

I made a little improvement of my fix by including template
type parameter to not dropping cv-const because they are similar to dependent
type which you cannot determine whether they are top-level cv-qualifier or not
until instantiation.

+         if (processing_template_decl
+               && (TREE_CODE (type) == TYPENAME_TYPE
+                  || TREE_CODE (type) == DECLTYPE_TYPE
++                  || TREE_CODE (type) == TEMPLATE_TYPE_PARM  // this is new
+                  )
+            )

1. It fix your test case of
template <class T>
struct A{
   void f(T);
};
template <class T>
void A<T>::f(const T){ }
template<>
void A<int[]>::f(const int*){}

current GCC mistakenly accepts without considering the gap of missing "const"
between declaration and out of line definition. clang correctly rejects it.
(https://www.godbolt.org/z/qb9Tf99eK) and explains the cause nicely.
My fix also rejects it.

2. It also fix a more obvious core1001 issue of free function as my previous fix
only deals with typename/decltype cases.
template<class T>
void f(const T){}
template<>
void f<int[3]>(const int*){}

Your comment is appreciated.

thank you

             reply	other threads:[~2021-10-03 11:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-03 11:14 Nick Huang [this message]
2021-10-03 20:16 ` Nick Huang
2021-10-07 20:50 ` [PATCH] c++: fix cases of core1001/1322 by not dropping cv-qualifier of function parameter of type of typename or decltype[PR101402,PR102033,PR102034,PR102039,PR102 Jason Merrill
2021-10-08 20:19 [PATCH] c++: fix cases of core1001/1322 by not dropping cv-qualifier of function parameter of type of typename or decltype[PR101402, PR102033, PR102034, PR102039, PR102 Nick Huang
2021-10-14 11:04 ` Nick Huang
2021-10-15 21:00   ` [PATCH] c++: fix cases of core1001/1322 by not dropping cv-qualifier of function parameter of type of typename or decltype[PR101402,PR102033,PR102034,PR102039,PR102 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=CAP6LXBt8JZoxjzuYMjO_K_QbdDKyP-FuxeboAC_MgfvxjyihzA@mail.gmail.com \
    --to=nickhuang99@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@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).