[PATCH] c++: Variable template and template parameter pack [PR96218]
Jason Merrill
jason@redhat.com
Mon Aug 3 19:51:56 GMT 2020
On 8/3/20 2:58 PM, Marek Polacek wrote:
> On Wed, Jul 29, 2020 at 05:56:56PM -0400, Jason Merrill via Gcc-patches wrote:
>> On 7/16/20 11:06 AM, Marek Polacek wrote:
>>> This is DR 2032 which says that the restrictions regarding template
>>> parameter packs and default arguments apply to variable templates as
>>> well, but we weren't detecting that.
>>>
>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>>>
>>> gcc/cp/ChangeLog:
>>>
>>> DR 2032
>>> PR c++/96218
>>> * pt.c (check_default_tmpl_args): Also consider variable
>>> templates.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> DR 2032
>>> PR c++/96218
>>> * g++.dg/cpp1y/var-templ67.C: New test.
>>> ---
>>> gcc/cp/pt.c | 5 +++--
>>> gcc/testsuite/g++.dg/cpp1y/var-templ67.C | 16 ++++++++++++++++
>>> 2 files changed, 19 insertions(+), 2 deletions(-)
>>> create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ67.C
>>>
>>> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
>>> index 4e1c77a6bd7..b74074a092b 100644
>>> --- a/gcc/cp/pt.c
>>> +++ b/gcc/cp/pt.c
>>> @@ -5481,14 +5481,15 @@ check_default_tmpl_args (tree decl, tree parms, bool is_primary,
>>> /* Don't complain about an enclosing partial
>>> specialization. */
>>> && parm_level == parms
>>> - && TREE_CODE (decl) == TYPE_DECL
>>> + && (TREE_CODE (decl) == TYPE_DECL || VAR_P (decl))
>>
>> Can we remove this part of the test entirely, since the enclosing if already
>> excludes functions?
>
> I'm afraid we can't -- we can still get here for function templates in C++98.
> Then we error like this:
>
> q.C:1:10: error: parameter pack ‘_Args’ must be at the end of the template parameter list
> 1 | template<typename... _Args, int... _Indexes>
Ah, I was forgetting that we allow libstdc++ variadic templates in C++98
mode even though they're part of C++11.
The patch is OK.
Jason
More information about the Gcc-patches
mailing list