public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105268] New: type/value mismatch when using variadic concept
@ 2022-04-13 23:05 barry.revzin at gmail dot com
2022-04-13 23:08 ` [Bug c++/105268] " mpolacek at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: barry.revzin at gmail dot com @ 2022-04-13 23:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105268
Bug ID: 105268
Summary: type/value mismatch when using variadic concept
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: barry.revzin at gmail dot com
Target Milestone: ---
>From StackOverflow (https://stackoverflow.com/q/71864544/2069064):
template<typename> concept C_one = true;
template<typename...> concept C_many = true;
template<bool B> struct S { };
template<typename T = S<C_one<int>>> void f(); // ok
template<typename T = S<C_many<int>>> void g(); // error
gcc rejects the declaration of g with:
<source>:7:35: error: type/value mismatch at argument 1 in template parameter
list for 'template<bool B> struct S'
7 | template<typename T = S<C_many<int>>> void g();
| ^~
<source>:7:35: note: expected a constant of type 'bool', got
'<template-parameter-1-1>'
But C_many<int> is a bool, so this should be fine. And template-parameter-1-1
isn't a very useful diagnostic anyway.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105268] type/value mismatch when using variadic concept
2022-04-13 23:05 [Bug c++/105268] New: type/value mismatch when using variadic concept barry.revzin at gmail dot com
@ 2022-04-13 23:08 ` mpolacek at gcc dot gnu.org
2022-04-14 2:05 ` mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-13 23:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105268
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
CC| |mpolacek at gcc dot gnu.org
Last reconfirmed| |2022-04-13
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105268] type/value mismatch when using variadic concept
2022-04-13 23:05 [Bug c++/105268] New: type/value mismatch when using variadic concept barry.revzin at gmail dot com
2022-04-13 23:08 ` [Bug c++/105268] " mpolacek at gcc dot gnu.org
@ 2022-04-14 2:05 ` mpolacek at gcc dot gnu.org
2022-04-14 17:29 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-14 2:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105268
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Looks like we mistakenly parse C_many<int> as a placeholder-type-specifier, and
things go wrong from there.
For C_one<int> cp_parser_placeholder_type_specifier -> finish_type_constraints
-> build_type_constraint -> build_concept_check -> build_standard_check ->
coerce_template_parms -> coerce_template_parms fails here:
8916 nargs = inner_args ? NUM_TMPL_ARGS (inner_args) : 0;
8917 if ((nargs - variadic_args_p > nparms && !variadic_p)
8918 || (nargs < nparms - variadic_p
8919 && require_all_args
8920 && !variadic_args_p
8921 && (!use_default_args
8922 || (TREE_VEC_ELT (parms, nargs) != error_mark_node
8923 && !TREE_PURPOSE (TREE_VEC_ELT (parms, nargs))))))
8924 {
8925 bad_nargs:
but for C_many<int> variadic_p is true so we don't return error_mark_node but
<type_argument_pack>.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105268] type/value mismatch when using variadic concept
2022-04-13 23:05 [Bug c++/105268] New: type/value mismatch when using variadic concept barry.revzin at gmail dot com
2022-04-13 23:08 ` [Bug c++/105268] " mpolacek at gcc dot gnu.org
2022-04-14 2:05 ` mpolacek at gcc dot gnu.org
@ 2022-04-14 17:29 ` mpolacek at gcc dot gnu.org
2022-04-15 15:35 ` cvs-commit at gcc dot gnu.org
2022-04-15 15:36 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-14 17:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105268
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105268] type/value mismatch when using variadic concept
2022-04-13 23:05 [Bug c++/105268] New: type/value mismatch when using variadic concept barry.revzin at gmail dot com
` (2 preceding siblings ...)
2022-04-14 17:29 ` mpolacek at gcc dot gnu.org
@ 2022-04-15 15:35 ` cvs-commit at gcc dot gnu.org
2022-04-15 15:36 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-15 15:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105268
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:ccae4443c8322d9d82a19a1e7c689413a122a478
commit r12-8176-gccae4443c8322d9d82a19a1e7c689413a122a478
Author: Marek Polacek <polacek@redhat.com>
Date: Thu Apr 14 13:48:15 2022 -0400
c++: wrong error with variadic concept [PR105268]
Here we issue a wrong error for the
template<typename T = S<C_many<int>>> void g();
line in the testcase. I surmise that's because we mistakenly parse
C_many<int> as a placeholder-type-specifier, and things go wrong from
there. We are in a default argument so we should reject parsing
C_many<int>
as a placeholder-type-specifier, which would mean creating a new parameter.
We want C_many<int> to be a concept-id instead.
It's interesting to see why the same problem didn't occur for C_one<int>.
In that case, cp_parser_placeholder_type_specifier ->
finish_type_constraints
-> build_type_constraint -> build_concept_check -> build_standard_check ->
coerce_template_parms fails the parse here:
8916 nargs = inner_args ? NUM_TMPL_ARGS (inner_args) : 0;
8917 if ((nargs - variadic_args_p > nparms && !variadic_p)
8918 || (nargs < nparms - variadic_p
8919 && require_all_args
8920 && !variadic_args_p
8921 && (!use_default_args
8922 || (TREE_VEC_ELT (parms, nargs) != error_mark_node
8923 && !TREE_PURPOSE (TREE_VEC_ELT (parms, nargs))))))
8924 {
8925 bad_nargs:
...
8943 return error_mark_node;
because nargs is 2 (the targs are <WILDCARD_DECL, int>) while nparms is
1 (for the one 'typename' in the tparam list of C_one). But for
C_many<int> variadic_p is true so we don't return error_mark_node but
<type_argument_pack>.
This patch does not issue any error for the !tentative case because
I didn't figure out how to trigger that. So it adds an assert instead.
PR c++/105268
gcc/cp/ChangeLog:
* parser.cc (cp_parser_placeholder_type_specifier): Return
error_mark_node when trying to build up a constrained parameter in
a default argument.
gcc/testsuite/ChangeLog:
* g++.dg/concepts/variadic6.C: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/105268] type/value mismatch when using variadic concept
2022-04-13 23:05 [Bug c++/105268] New: type/value mismatch when using variadic concept barry.revzin at gmail dot com
` (3 preceding siblings ...)
2022-04-15 15:35 ` cvs-commit at gcc dot gnu.org
@ 2022-04-15 15:36 ` mpolacek at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-15 15:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105268
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 12.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-04-15 15:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 23:05 [Bug c++/105268] New: type/value mismatch when using variadic concept barry.revzin at gmail dot com
2022-04-13 23:08 ` [Bug c++/105268] " mpolacek at gcc dot gnu.org
2022-04-14 2:05 ` mpolacek at gcc dot gnu.org
2022-04-14 17:29 ` mpolacek at gcc dot gnu.org
2022-04-15 15:35 ` cvs-commit at gcc dot gnu.org
2022-04-15 15:36 ` mpolacek 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).