Bug 1802608

Summary: g++ rejects a valid code
Product: Red Hat Developer Toolset Reporter: Joe Wright <jwright>
Component: gccAssignee: Marek Polacek <mpolacek>
Status: CLOSED ERRATA QA Contact: Alexandra Petlanová Hájková <ahajkova>
Severity: high Docs Contact:
Priority: unspecified    
Version: DTS 9.0 RHEL 7CC: ahajkova, alanm, casantos, fweimer, jakub, kwalker, law, mcermak, mkolbas, mnewsome, mpolacek, ohudlick, pandrade, sipoyare, tborcin
Target Milestone: alphaKeywords: Triaged
Target Release: 9.1   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: devtoolset-9-gcc-9.3.1-1.el7 Doc Type: Bug Fix
Doc Text:
Cause: A mismatch in template argument deduction. Consequence: Valid C++ code would fail to compile. Fix: Don't reduce the template level of template parameters when performing template argument deduction substitution. Result: The code compiles correctly.
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-05-26 06:07:39 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joe Wright 2020-02-13 14:32:08 UTC
Description of problem:

=== Console ===
~/tmp$ g++-9.1.0 -c test.cpp
test.cpp: In member function ‘void S<T>::bar()’:
test.cpp:11:20: error: no matching function for call to ‘S<T>::foo<void>(int)’
   11 |         foo<void>(1);
      |                    ^
test.cpp:5:17: note: candidate: ‘template<class T> template<class U, class V> static void S<T>::foo(V)’
    5 |     static void foo(V)
      |                 ^~~
test.cpp:5:17: note:   template argument deduction/substitution failed:
test.cpp:11:20: note:   mismatched types ‘V’ and ‘int’
   11 |         foo<void>(1);
      |       
===

Version-Release number of selected component (if applicable):
latest

How reproducible:
=== test.cpp ===
template <class T>
struct S
{
    template <class U, class V>
    static void foo(V)
    {
    }
    
    void bar()
    {
        foo<void>(1);
    }
};
===

Steps to Reproduce:
1.See above
2.
3.

Actual results:
See description

Expected results:


Additional info:

This is reported upstream in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90505 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92221 

This also appears to be a regressiopn from a previous fix: https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=265734

Comment 2 Marek Polacek 2020-02-13 15:02:28 UTC
Thanks for the report, I will restart my work on the fix next week (I'm on PTO today and Friday).

Also fixing the component.

Comment 4 Marek Polacek 2020-03-04 13:01:17 UTC
Fixed upstream: https://gcc.gnu.org/g:6b3302da9ef26aa11940f8c0dc92bec19e15c09b

Comment 5 Marek Polacek 2020-03-04 23:53:24 UTC
Fixed in gcc 9 too: https://gcc.gnu.org/g:581825efc30ce79d86dfb0ebf378913fdec44adf

Comment 16 errata-xmlrpc 2020-05-26 06:07:39 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:2274