public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
@ 2021-08-24  9:25 nickhuang99 at hotmail dot com
  2021-08-24  9:33 ` [Bug c++/102033] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-08-24  9:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

            Bug ID: 102033
           Summary: template function signature incorrectly drops
                    top-level cv-qualifiers causing template
                    specialization failing to match
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nickhuang99 at hotmail dot com
  Target Milestone: ---

The following snippet code fails with similar reason as PR101402, but it cannot
be fixed with similar way of using *resolve_typename_type* without further
improvement of itself.

template<class TA>
struct A{
        template<class TB>
        using Type=TB[3];
};
template<class TA, class TB>
void f(const typename A<TA>::template Type<TB>){}
template <>
void f<int, char>(const typename A<int>::template Type<char>){}


error: template-id 'f<int, char>' for 'void f(const char*)' does not match any
template declaration
    9 | void f<int, char>(const typename A<int>::template Type<char>){}
      |      ^~~~~~~~~~~~
array-using.cpp:7:6: note: candidate is: 'template<class TA, class TB> void
f(typename A<TA>::Type<TB>)'
    7 | void f(const typename A<TA>::template Type<TB>){}
      |      ^

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
@ 2021-08-24  9:33 ` pinskia at gcc dot gnu.org
  2021-08-24  9:42 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-24  9:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-24
             Blocks|                            |24666
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, looks like an array is not decaying to a pointer issue or decaying
too early really.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24666
[Bug 24666] [meta-bug] array decaying to pointers

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
  2021-08-24  9:33 ` [Bug c++/102033] " pinskia at gcc dot gnu.org
@ 2021-08-24  9:42 ` pinskia at gcc dot gnu.org
  2021-08-24 10:12 ` nickhuang99 at hotmail dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-24  9:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 102034 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
  2021-08-24  9:33 ` [Bug c++/102033] " pinskia at gcc dot gnu.org
  2021-08-24  9:42 ` pinskia at gcc dot gnu.org
@ 2021-08-24 10:12 ` nickhuang99 at hotmail dot com
  2021-08-24 11:28 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-08-24 10:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

--- Comment #3 from qingzhe huang <nickhuang99 at hotmail dot com> ---
I can give tons of similar cases with even more complicated template levels
combined with using/typedefs/default arguments. i.e.

template<class TA>
struct A{
        template<class TB>
        struct B{
                using TB_Alias=TB;
                template<class TC=TB_Alias>
                struct C{
                        typedef TC Arr3[3];
                };
        };
};
template<class TA, class TB>
void f(const typename A<TA>::template B<TB>::template C<>::Arr3){}
template <>
void f<int, char>(const typename A<int>::template B<char>::template
C<>::Arr3){}

The fix are all can be done similarly at point to calculating function
parameter "cv-qualifier" value by passing its result into call
*cp_build_qualified_type* at  decl.c:grokparms.

for example:

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3414cbdc876..473c7b7d75c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14493,7 +14493,16 @@ grokparms (tree parmlist, tree *parms)

          /* Top-level qualifiers on the parameters are
             ignored for function types.  */
-         type = cp_build_qualified_type (type, 0);
+         int type_quals = 0;
+         /* Top-level qualifiers are reserved for array type. PR101402 */
+         if (TREE_CODE (type) == TYPENAME_TYPE)
+         {
+            tree resolved_type = resolve_typename_type(type, false);
+            if (resolved_type && TREE_CODE(resolved_type) == ARRAY_TYPE)
+               type_quals = CP_TYPE_CONST_P(type);
+         }
+         type = cp_build_qualified_type (type, type_quals);
+
          if (TREE_CODE (type) == METHOD_TYPE)
            {
              error ("parameter %qD invalidly declared method type", decl);



However, original *resolve_typename_type* function is not working well to cover
all cases. I only fixed one "non-recursive" case with 

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 020a4bf2f6d..1944bf4a6ea 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -27989,7 +27989,12 @@ resolve_typename_type (tree type, bool only_current_p)

   /* If we failed to resolve it, return the original typename.  */
   if (!result)
-    return type;
+  {
+         if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR
+                         && TREE_CODE (decl) == TEMPLATE_DECL)
+                 return TREE_TYPE(decl);
+         return type;
+  }

   /* If lookup found a typename type, resolve that too.  */
   if (TREE_CODE (result) == TYPENAME_TYPE && !TYPENAME_IS_RESOLVING_P
(result))



And then I give up because it requires almost a new *resolve_typename_type*
function to cover all possible cases. And I have no GCC write access and the
code is extremely difficult to maintain.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
                   ` (2 preceding siblings ...)
  2021-08-24 10:12 ` nickhuang99 at hotmail dot com
@ 2021-08-24 11:28 ` redi at gcc dot gnu.org
  2021-08-24 13:39 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-24 11:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> And I have no GCC write access and the code is extremely difficult to maintain.

We don't just give people write access as soon as they propose a patch (does
any serious software proejct do that?!)

The contribution process is documented at
https://gcc.gnu.org/contribute.html#patches and write access policies at
https://gcc.gnu.org/gitwrite.html#policies

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
                   ` (3 preceding siblings ...)
  2021-08-24 11:28 ` redi at gcc dot gnu.org
@ 2021-08-24 13:39 ` redi at gcc dot gnu.org
  2021-08-24 15:29 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-24 13:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 102038 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
                   ` (4 preceding siblings ...)
  2021-08-24 13:39 ` redi at gcc dot gnu.org
@ 2021-08-24 15:29 ` redi at gcc dot gnu.org
  2021-10-15 21:00 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-24 15:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 102042 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
                   ` (5 preceding siblings ...)
  2021-08-24 15:29 ` redi at gcc dot gnu.org
@ 2021-10-15 21:00 ` cvs-commit at gcc dot gnu.org
  2021-10-25  9:02 ` nickhuang99 at hotmail dot com
  2021-12-09  4:45 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-15 21:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:79802c5dcc043a515f429bb2bec7573b8537c32a

commit r12-4453-g79802c5dcc043a515f429bb2bec7573b8537c32a
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Sep 28 10:02:04 2021 -0400

    c++: array cv-quals and template specialization [PR101402]

    PRs 101402, 102033, etc. demonstrated that the fix for PR92010 wasn't
    handling all cases of the CWG1001/1322 issue with parameter type qual
    stripping and arrays with templates.  The problem turned out to be in
    determine_specialization, which did an extra substitution without the 92010
    fix and then complained that the result didn't match.

    But just removing that wrong/redundant code meant that we were accepting
    specializations with different numbers of parameters, because the code in
    fn_type_unification that compares types in this case wasn't checking for
    length mismatch.

    After fixing that, I realized that fn_type_unification couldn't tell the
    difference between variadic and non-variadic function types, because the
    args array doesn't include the terminal void we use to indicate
non-variadic
    function type.  So I added it, and made the necessary adjustments.

    Thanks to qingzhe "nick" huang <nickhuang99@hotmail.com> for the patch that
    led me to dig more into this, and the extensive testcases.

            PR c++/51851
            PR c++/101402
            PR c++/102033
            PR c++/102034
            PR c++/102039
            PR c++/102044

    gcc/cp/ChangeLog:

            * pt.c (determine_specialization): Remove redundant code.
            (fn_type_unification): Check for mismatched length.
            (type_unification_real): Ignore terminal void.
            (get_bindings): Don't stop at void_list_node.
            * class.c (resolve_address_of_overloaded_function): Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/template/fnspec2.C: New test.
            * g++.dg/template/parm-cv1.C: New test.
            * g++.dg/template/parm-cv2.C: New test.
            * g++.dg/template/parm-cv3.C: New test.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
                   ` (6 preceding siblings ...)
  2021-10-15 21:00 ` cvs-commit at gcc dot gnu.org
@ 2021-10-25  9:02 ` nickhuang99 at hotmail dot com
  2021-12-09  4:45 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: nickhuang99 at hotmail dot com @ 2021-10-25  9:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

qingzhe huang <nickhuang99 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from qingzhe huang <nickhuang99 at hotmail dot com> ---
fixed by patch under PR101402

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/102033] template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match
  2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
                   ` (7 preceding siblings ...)
  2021-10-25  9:02 ` nickhuang99 at hotmail dot com
@ 2021-12-09  4:45 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-09  4:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102033

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-12-09  4:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24  9:25 [Bug c++/102033] New: template function signature incorrectly drops top-level cv-qualifiers causing template specialization failing to match nickhuang99 at hotmail dot com
2021-08-24  9:33 ` [Bug c++/102033] " pinskia at gcc dot gnu.org
2021-08-24  9:42 ` pinskia at gcc dot gnu.org
2021-08-24 10:12 ` nickhuang99 at hotmail dot com
2021-08-24 11:28 ` redi at gcc dot gnu.org
2021-08-24 13:39 ` redi at gcc dot gnu.org
2021-08-24 15:29 ` redi at gcc dot gnu.org
2021-10-15 21:00 ` cvs-commit at gcc dot gnu.org
2021-10-25  9:02 ` nickhuang99 at hotmail dot com
2021-12-09  4:45 ` pinskia at gcc dot gnu.org

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).