c++: bad 'this' conversion for nullary memfn [PR106760]
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Testing passed
|
Commit Message
Bootstrapped and regtested on x86_64-pc-linu-xgnu, does this look OK for trunk?
-- >8 --
Here we notice the 'this' conversion for the call f<void>() is bad, so
we correctly defer instantiating it, but we end up never adding it to
'bad_fns' since missing_conversion_p for it returns false (its only
argument is the already computed 'this' argument). This is not a huge
deal, but it causes us to longer accept the call with -fpermissive.
So if we have a non-strictly viable template candidate that has not been
instantiated, then we need to add it to 'bad_fns' even if it doesn't
have any missing conversions.
PR c++/106760
gcc/cp/ChangeLog:
* call.cc (add_candidates): Relax test for adding a candidate
to 'bad_fns' to accept an uninstantiated template candidate that
has no missing conversions.
gcc/testsuite/ChangeLog:
* g++.dg/ext/conv3.C: New test.
---
gcc/cp/call.cc | 3 ++-
gcc/testsuite/g++.dg/ext/conv3.C | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/ext/conv3.C
Comments
On 6/2/23 11:55, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linu-xgnu, does this look OK for trunk?
>
> -- >8 --
>
> Here we notice the 'this' conversion for the call f<void>() is bad, so
> we correctly defer instantiating it, but we end up never adding it to
> 'bad_fns' since missing_conversion_p for it returns false (its only
> argument is the already computed 'this' argument). This is not a huge
> deal, but it causes us to longer accept the call with -fpermissive.
>
> So if we have a non-strictly viable template candidate that has not been
> instantiated, then we need to add it to 'bad_fns' even if it doesn't
> have any missing conversions.
I wonder about using ck_deferred_bad in add_template_candidate for this
case rather than changing the test here? OK either way.
> PR c++/106760
>
> gcc/cp/ChangeLog:
>
> * call.cc (add_candidates): Relax test for adding a candidate
> to 'bad_fns' to accept an uninstantiated template candidate that
> has no missing conversions.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/conv3.C: New test.
> ---
> gcc/cp/call.cc | 3 ++-
> gcc/testsuite/g++.dg/ext/conv3.C | 16 ++++++++++++++++
> 2 files changed, 18 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/ext/conv3.C
>
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index 2736f55f229..dbf42567cc9 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -6632,7 +6632,8 @@ add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
>
> if (cand->viable == -1
> && shortcut_bad_convs
> - && missing_conversion_p (cand))
> + && (TREE_CODE (cand->fn) == TEMPLATE_DECL
> + || missing_conversion_p (cand)))
> {
> /* This candidate has been tentatively marked non-strictly viable,
> and we didn't compute all argument conversions for it (having
> diff --git a/gcc/testsuite/g++.dg/ext/conv3.C b/gcc/testsuite/g++.dg/ext/conv3.C
> new file mode 100644
> index 00000000000..5f4b4d4cc50
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/conv3.C
> @@ -0,0 +1,16 @@
> +// PR c++/106760
> +// { dg-additional-options "-fpermissive" }
> +
> +struct S {
> + template<class>
> + int f(...);
> +
> + int g() const {
> + return f<void>(); // { dg-warning "discards qualifiers" }
> + }
> +};
> +
> +int main() {
> + S s;
> + s.g();
> +}
@@ -6632,7 +6632,8 @@ add_candidates (tree fns, tree first_arg, const vec<tree, va_gc> *args,
if (cand->viable == -1
&& shortcut_bad_convs
- && missing_conversion_p (cand))
+ && (TREE_CODE (cand->fn) == TEMPLATE_DECL
+ || missing_conversion_p (cand)))
{
/* This candidate has been tentatively marked non-strictly viable,
and we didn't compute all argument conversions for it (having
new file mode 100644
@@ -0,0 +1,16 @@
+// PR c++/106760
+// { dg-additional-options "-fpermissive" }
+
+struct S {
+ template<class>
+ int f(...);
+
+ int g() const {
+ return f<void>(); // { dg-warning "discards qualifiers" }
+ }
+};
+
+int main() {
+ S s;
+ s.g();
+}