Bug 101402 - [DR 1001] top cv qualifier not dropped for array type typedef in template class
Summary: [DR 1001] top cv qualifier not dropped for array type typedef in template class
Status: RESOLVED DUPLICATE of bug 51851
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-10 02:58 UTC by qingzhe huang
Modified: 2021-10-15 21:00 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-07-12 00:00:00


Attachments
a diagnositic message to print functions arguments for comparison (487 bytes, text/plain)
2021-07-10 02:58 UTC, qingzhe huang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description qingzhe huang 2021-07-10 02:58:25 UTC
Created attachment 51127 [details]
a diagnositic message to print functions arguments for comparison

This example code from core 1001(http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1001) is still giving no matching template declaration error.

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


1. This happens for all gcc versions. The root cause is template function argument is considered as ‘(const int*)’ instead of ‘(int*)’ (see attached debug output for details.)

2. C++ standard requires top level cv qualifier being dropped when forming function type.(https://timsong-cpp.github.io/cppwp/dcl.fct#5)

3. When both 'const' are removed from template function and specialization, there is no error which proves array type works as long as there is no top level cv qualifier.

4. I feel this is rather a high-profile bug as the example code is listed in active core language issues long ago, particularly when both clang and MSVC have fixed this issue. (see godbolt: https://www.godbolt.org/z/cofrEWEbs)
Comment 1 Jonathan Wakely 2021-07-12 10:51:00 UTC
(In reply to nick huang from comment #0)
> This example code from core
> 1001(http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1001) is
> still giving no matching template declaration error.

The issue is still open and has not been resolved yet.

> 2. C++ standard requires top level cv qualifier being dropped when forming
> function type.(https://timsong-cpp.github.io/cppwp/dcl.fct#5)

Yes, that's what the issue quotes, and it also says "It is not clear how or whether this adjustment should be applied to parameters of function templates when the parameter has a dependent type, however."

> 
> 3. When both 'const' are removed from template function and specialization,
> there is no error which proves array type works as long as there is no top
> level cv qualifier.
> 
> 4. I feel this is rather a high-profile bug as the example code is listed in
> active core language issues long ago,

The issue is still active, meaning the standard has not been fixed to say what the correct behaviour is.
Comment 2 Marek Polacek 2021-07-12 16:57:37 UTC
We already have a bug for this.

*** This bug has been marked as a duplicate of bug 51851 ***
Comment 3 qingzhe huang 2021-08-23 12:24:29 UTC
bug 51851 has been fixed by latest release/gcc-10, but not this issue. So, I suggest to change this bug status to New.
Comment 4 GCC Commits 2021-10-15 21:00:40 UTC
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.