public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: nick huang <nickhuang99@hotmail.com>
To: Jason Merrill <jason@redhat.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: *PING* [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,PR102044]
Date: Sat, 25 Sep 2021 19:15:51 +0000	[thread overview]
Message-ID: <DM5PR0501MB37339BC4714DD2A1DCBF2FE5B5A59@DM5PR0501MB3733.namprd05.prod.outlook.com> (raw)
In-Reply-To: <5757d35b-3562-5ab8-5062-8ff806d32693@redhat.com>

Hi Jason,

Sorry for not noticing your response.

>>Unfortunately, your patch breaks
>>
>>template <class T>
>>struct A
>>{
>>   void f(T);
>>};
>>template <class T>
>>void A<T>::f(const T)
>>{ }

1. Perhaps I misunderstand your comment, but my patch does NOT fix this issue. Neither does current GCC fix this code, if it is incorrect grammatically. In other words,  tested in www.godbolt.org and all major compilers accept it.  And my patch does NOT affects GCC current behavior, meaning my patched GCC still accepts it like now. So, I don't think my patch breaks it because this code is never fixed. (Whether this code is correct or not, I keep an open mind.)


>>which is certainly questionable code, but is currently also accepted by 
>>clang and EDG compilers.

2. Like I said above, I am not even sure if it is an issue since most compilers accept it. But my patch does NOT touch this issue at all. In essential, my patch ONLY deals with dependent type starting with keyword "typename" or "decltype". Just like my email subject, my patch only fixes one particular case of this "family" of bugs, that is "typename" or "decltype" cases.

>>Why doesn't the PR92010 fix address these testcases as well?

3. PR92010 creates new functions of "rebuild_function_or_method_type" and by using gdb to trace PR101402 code as following:

template<class T> struct A {
     typedef T arr[3];
};
template<class T> void f(const typename A<T>::arr) { }    // #1
template void f<int>(const A<int>::arr);                                   // #2

I added some print function declaration code before and after calling "maybe_rebuild_function_decl_type" to print out its parameter "r" which is function declaration inside "tsubst_function_decl". 
Here is the result:
a) Before calling, the function declaration is "void f(int*)" and after calling, it is adjusted to correct one as "void f(const int*)". However, after this line "SET_DECL_IMPLICIT_INSTANTIATION (r);",  it fallback to original dependent type as "void f(typename A<T>::arr) [with T = int; typename A<T>::arr = int [3]]" till end. This completely defeats the purpose of template substitution effort.  

b) On the other hand, by screening input parameter of "rebuild_function_or_method_type", I can see it is using an incorrect function type as  "void(typename A<T>::arr)" which already drops "const" prematurely.  This is due to previous #1 template function declaration parsing. So, This gives us the clear idea of the root cause of this kind of bugs. It happens during template function declaration stage #1 when producing template declarator.  Instead of doing a later-correction-effort in PR92010, my patch tries to at least avoid dropping "const" in case of "typename" and "decltype" during template function declaration stage in #1.   

Best regards,

Qingzhe Huang

From: Jason Merrill <jason@redhat.com>
Sent: September 24, 2021 3:11 PM
To: nick huang <nickhuang99@hotmail.com>; gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>
Subject: Re: *PING* [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,PR102044] 
 
I already responded to this patch:

https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579527.html

  reply	other threads:[~2021-09-25 19:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 13:55 nick huang
2021-09-15 23:00 ` Jason Merrill
2021-09-24 11:14 ` *PING* " nick huang
2021-09-24 19:11   ` Jason Merrill
2021-09-25 19:15     ` nick huang [this message]
2021-09-28 14:00       ` Jason Merrill
2021-09-27  3:40     ` nick huang

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=DM5PR0501MB37339BC4714DD2A1DCBF2FE5B5A59@DM5PR0501MB3733.namprd05.prod.outlook.com \
    --to=nickhuang99@hotmail.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).