Bug 85864 - [8/9 Regression] template argument string literal operator with default argument doesnt work in templates
Summary: [8/9 Regression] template argument string literal operator with default argum...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.1.0
: P2 normal
Target Milestone: 8.2
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2018-05-21 19:53 UTC by Lars Bonnichsen
Modified: 2018-05-24 14:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.3.0
Known to fail: 8.1.0, 9.0
Last reconfirmed: 2018-05-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Bonnichsen 2018-05-21 19:53:43 UTC
The following code compiles with GCC 7.3.0 and earlier, but errors with GCC 8.1.0 and trunk.

template<class T, T... S> struct String_template {};

template<class C, C... S>
constexpr String_template<C, S...> operator""_template() {
    return String_template<C, S...> {};
}

template<class prefix = decltype("0x"_template), class T>
int hex(T v) { return 1; }

template<int v> 
void tt2() {
    auto h2 = hex<decltype("0x"_template)>(1);
    auto h = hex(2);
}

int main() {
    auto h = hex(2);
    return h;
}

<source>: In function 'void tt2()':

<source>:14:19: error: no matching function for call to 'hex(int)'

     auto h = hex(2);

                   ^

<source>:9:5: note: candidate: 'template<class prefix, class T> int hex(T)'

 int hex(T v) { return 1; }

     ^~~

<source>:9:5: note:   template argument deduction/substitution failed:

The error is only triggered by hex(2).
The error may be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85731
Comment 1 Jonathan Wakely 2018-05-21 23:17:00 UTC
I'm not sure if this is valid, but it started to be rejected with with r258039

            PR c++/84489 - dependent default template argument
    
            * pt.c (type_unification_real): Handle early substitution failure.
Comment 2 Jason Merrill 2018-05-24 14:27:41 UTC
Author: jason
Date: Thu May 24 14:27:10 2018
New Revision: 260672

URL: https://gcc.gnu.org/viewcvs?rev=260672&root=gcc&view=rev
Log:
	PR c++/85864 - literal template and default template arg.

	* pt.c (instantiation_dependent_r): Handle NONTYPE_ARGUMENT_PACK.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/udlit-char-template2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 3 Jason Merrill 2018-05-24 14:29:36 UTC
Author: jason
Date: Thu May 24 14:29:05 2018
New Revision: 260674

URL: https://gcc.gnu.org/viewcvs?rev=260674&root=gcc&view=rev
Log:
	PR c++/85864 - literal template and default template arg.

	* pt.c (instantiation_dependent_r): Handle NONTYPE_ARGUMENT_PACK.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/cpp1y/udlit-char-template2.C
Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/pt.c
Comment 4 Jason Merrill 2018-05-24 14:36:25 UTC
Fixed.