public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/12672] Evals template defaults args that it should not
[not found] <bug-12672-4@http.gcc.gnu.org/bugzilla/>
@ 2021-08-25 20:49 ` ppalka at gcc dot gnu.org
2021-08-31 17:31 ` cvs-commit at gcc dot gnu.org
2021-09-13 15:09 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-08-25 20:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
CC| |ppalka at gcc dot gnu.org
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12672] Evals template defaults args that it should not
[not found] <bug-12672-4@http.gcc.gnu.org/bugzilla/>
2021-08-25 20:49 ` [Bug c++/12672] Evals template defaults args that it should not ppalka at gcc dot gnu.org
@ 2021-08-31 17:31 ` cvs-commit at gcc dot gnu.org
2021-09-13 15:09 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-31 17:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
--- Comment #15 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:f1e7319956928712e8bf4893ebdfeeb6441099ee
commit r12-3271-gf1e7319956928712e8bf4893ebdfeeb6441099ee
Author: Patrick Palka <ppalka@redhat.com>
Date: Tue Aug 31 13:31:10 2021 -0400
c++: check arity before deduction w/ explicit targs [PR12672]
During overload resolution, when the arity of a function template
clearly disagrees with the arity of the call, no specialization of the
function template could yield a viable candidate. The deduction routine
type_unification_real already notices this situation, but not before
it substitutes explicit template arguments into the template, a step
which could induce a hard error. Although it's necessary to perform
this substitution first in order to check arity perfectly (since the
substitution can e.g. expand a non-trailing parameter pack), in most
cases we can determine ahead of time whether there's an arity
disagreement without needing to perform deduction at all.
To that end, this patch implements an (approximate) arity check in
add_template_candidate_real that guards actual deduction. It's enabled
only when there are explicit template arguments since that's when
deduction can force otherwise avoidable template instantiations. (I
experimented with enabling it unconditionally as an optimization, and
observed some improvements to compile time of about 5% but also some
slowdowns of about the same magnitude, so kept it conditional.)
In passing, this adds a least_p parameter to arity_rejection for sake
of consistent diagnostics with unify_arity.
A couple of testcases needed to be adjusted so that deduction continues
to occur as intended after this change. Except in unify6.C, where we
were expecting foo<void ()> to be ill-formed due to substitution
forming a function type with an added 'const', but ISTM this is
permitted by [dcl.fct]/7, so I changed the test accordingly.
PR c++/12672
gcc/cp/ChangeLog:
* call.c (rejection_reason::call_varargs_p): Rename this
previously unused member to ...
(rejection_reason::least_p): ... this.
(arity_rejection): Add least_p parameter.
(add_template_candidate_real): When there are explicit
template arguments, check that the arity of the call agrees with
the arity of the function before attempting deduction.
(print_arity_information): Add least_p parameter.
(print_z_candidate): Adjust call to print_arity_information.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/decltype29.C: Adjust.
* g++.dg/template/error56.C: Adjust.
* g++.old-deja/g++.pt/unify6.C: Adjust.
* g++.dg/template/explicit-args7.C: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12672] Evals template defaults args that it should not
[not found] <bug-12672-4@http.gcc.gnu.org/bugzilla/>
2021-08-25 20:49 ` [Bug c++/12672] Evals template defaults args that it should not ppalka at gcc dot gnu.org
2021-08-31 17:31 ` cvs-commit at gcc dot gnu.org
@ 2021-09-13 15:09 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-13 15:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #16 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12 by accepting such code, which is permitted but not required by
the standard.
^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <bug-12672-6594@http.gcc.gnu.org/bugzilla/>]
* [Bug c++/12672] New: Evals template defaults args that it should not
@ 2003-10-18 8:24 igodard at pacbell dot net
2003-10-18 8:26 ` [Bug c++/12672] " igodard at pacbell dot net
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: igodard at pacbell dot net @ 2003-10-18 8:24 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
Summary: Evals template defaults args that it should not
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: igodard at pacbell dot net
CC: gcc-bugs at gcc dot gnu dot org
The compiler tries to evaluate template default arguments on a result type of an overloaded call on a template function for an overload that cannot be the correct candidate.
The actual call has two args, and the templated overload with two formals is the target of the call. However, there is also a templated overload with only one argument. That one-arg function has a result type which is itself a template with default args. The compiler tries to evaluate the default args for the type of the template and it blows up because it's undefined for that type.
The problem seems to be that the compiler is not first pruning all candidates with the wrong number of formals before doing type matching. These candidates cannot be the matching overload because they have the wrong number of args. So the compiler is trying to do type matching on impossible overloads, and if that matching (correctly) gets in trouble then you get an error, whereas if arg-number pruning were first then you would get a correct match and no error.
The particular error in the test case is that the evaluation of a default template argument of a type used by the function calls for a member type that doesn't exist for the actual type. However, the actual error in the test doesn't matter - anything that would cause an error during type matching on the wrong (impossible) overload would do.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12672] Evals template defaults args that it should not
2003-10-18 8:24 [Bug c++/12672] New: " igodard at pacbell dot net
@ 2003-10-18 8:26 ` igodard at pacbell dot net
2003-10-18 11:28 ` igodard at pacbell dot net
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: igodard at pacbell dot net @ 2003-10-18 8:26 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
------- Additional Comments From igodard at pacbell dot net 2003-10-18 08:24 -------
Created an attachment (id=4956)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=4956&action=view)
Compiler output (-v -save-temps)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12672] Evals template defaults args that it should not
2003-10-18 8:24 [Bug c++/12672] New: " igodard at pacbell dot net
2003-10-18 8:26 ` [Bug c++/12672] " igodard at pacbell dot net
@ 2003-10-18 11:28 ` igodard at pacbell dot net
2003-10-18 16:19 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: igodard at pacbell dot net @ 2003-10-18 11:28 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
------- Additional Comments From igodard at pacbell dot net 2003-10-18 08:26 -------
Created an attachment (id=4957)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=4957&action=view)
Source code (-save-temps)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12672] Evals template defaults args that it should not
2003-10-18 8:24 [Bug c++/12672] New: " igodard at pacbell dot net
2003-10-18 8:26 ` [Bug c++/12672] " igodard at pacbell dot net
2003-10-18 11:28 ` igodard at pacbell dot net
@ 2003-10-18 16:19 ` pinskia at gcc dot gnu dot org
2003-10-18 19:50 ` bangerth at dealii dot org
2003-12-28 22:13 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-18 16:19 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-10-18 15:46 -------
Here is the example without an extra includes, I have not looked to see what the standard says
abou this though:
template<typename i> class it
{
typedef typename i::iterator_category iterator_category;
};
template<typename U>
class UT { public: U u;};
template<typename U,
typename C = typename it<U>::iterator_category>
class Aux {
public:
typedef UT<U> R;
};
template<typename T> class R { public: T t;};
template<typename T>
typename Aux<T>::R Foo(T t) { return 0; }
template<typename T>
void Foo(T, T);
void Foo(int, int) { }
template<typename T>
T Bar(T, T);
inline int Bar(int i1, int i2) { return i1; }
inline char Bar(char c1, char c2) { return c1; }
int main() {
Bar(0, 1);
Bar<char>(0, 1);
Bar<int>(0, 1);
Foo(1, 2);
Foo<int>(1, 2);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12672] Evals template defaults args that it should not
2003-10-18 8:24 [Bug c++/12672] New: " igodard at pacbell dot net
` (2 preceding siblings ...)
2003-10-18 16:19 ` pinskia at gcc dot gnu dot org
@ 2003-10-18 19:50 ` bangerth at dealii dot org
2003-12-28 22:13 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2003-10-18 19:50 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2003-10-18 19:47:24
date| |
------- Additional Comments From bangerth at dealii dot org 2003-10-18 19:47 -------
Confirmed. Here's something even shorter:
---------------------------
template <typename T> struct S {
typedef typename T::type type;
};
template<typename U, typename V = typename S<U>::type>
struct A {};
template<typename T> A<T> Foo(T);
template<typename T> void Foo(T, T);
int main() {
Foo<int>(1, 2);
}
----------------------------
This fails to compile because the compiler tries to instantiate
the return type of the first Foo function. Whether that is actually
taken is irrelevant here, since we are only doing name lookup at this
stage, but we shouldn't error out: this is a SFINAE failure and
should just remove the first Foo function from the list of candidates.
It shouldn't be an error.
I confirm this for 3.3 and 3.4 builds from 2003-09-19, since this is
the latest I presently have. They both say
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc
x.cc: In instantiation of `S<int>':
x.cc:12: instantiated from here
x.cc:2: error: `int' is not a class, struct, or union type
What startles me a bit is that icc7 also shows the error. I am pretty sure,
though, that this is in error as well.
W.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/12672] Evals template defaults args that it should not
2003-10-18 8:24 [Bug c++/12672] New: " igodard at pacbell dot net
` (3 preceding siblings ...)
2003-10-18 19:50 ` bangerth at dealii dot org
@ 2003-12-28 22:13 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-12-28 22:13 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Last reconfirmed|2003-10-18 19:47:24 |2003-12-28 21:40:24
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12672
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-09-13 15:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-12672-4@http.gcc.gnu.org/bugzilla/>
2021-08-25 20:49 ` [Bug c++/12672] Evals template defaults args that it should not ppalka at gcc dot gnu.org
2021-08-31 17:31 ` cvs-commit at gcc dot gnu.org
2021-09-13 15:09 ` ppalka at gcc dot gnu.org
[not found] <bug-12672-6594@http.gcc.gnu.org/bugzilla/>
2009-04-16 17:02 ` igodard at pacbell dot net
2003-10-18 8:24 [Bug c++/12672] New: " igodard at pacbell dot net
2003-10-18 8:26 ` [Bug c++/12672] " igodard at pacbell dot net
2003-10-18 11:28 ` igodard at pacbell dot net
2003-10-18 16:19 ` pinskia at gcc dot gnu dot org
2003-10-18 19:50 ` bangerth at dealii dot org
2003-12-28 22:13 ` pinskia at gcc dot gnu dot 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).