public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: mark_single_function and SFINAE [PR108282]
@ 2023-01-04 16:37 Patrick Palka
  2023-01-04 19:05 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-01-04 16:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

We typically ignore mark_used failure when in a non-SFINAE context for
sake of better error recovery.  But in mark_single_function we're
instead ignoring mark_used failure in a SFINAE context, which ends up
causing the second static_assert here to incorrectly fail.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/12?

	PR c++/108282

gcc/cp/ChangeLog:

	* decl2.cc (mark_single_function): Ignore mark_used failure
	only in a non-SFINAE context rather than in a SFINAE one.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/concepts-requires34.C: New test.
---
 gcc/cp/decl2.cc                               |  2 +-
 .../g++.dg/cpp2a/concepts-requires34.C        | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C

diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
index f95529a5c9a..00ed64d1691 100644
--- a/gcc/cp/decl2.cc
+++ b/gcc/cp/decl2.cc
@@ -5600,7 +5600,7 @@ mark_single_function (tree expr, tsubst_flags_t complain)
 
   if (is_overloaded_fn (expr) == 1
       && !mark_used (expr, complain)
-      && (complain & tf_error))
+      && !(complain & tf_error))
     return false;
   return true;
 }
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C
new file mode 100644
index 00000000000..670a6dab31a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C
@@ -0,0 +1,19 @@
+// PR c++/108282
+// { dg-do compile { target c++20 } }
+
+template<class T>
+concept TEST = requires { T::TT; };
+
+struct C { };
+
+template<class AT>
+struct B {
+  static inline void TT() requires TEST<AT>;
+};
+
+int main() {
+  static_assert( !TEST<C> );
+  static_assert( !TEST<B<C>> );
+
+  B<C>::TT();  // { dg-error "no match" }
+}
-- 
2.39.0.158.g2b4f5a4e4b


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: mark_single_function and SFINAE [PR108282]
  2023-01-04 16:37 [PATCH] c++: mark_single_function and SFINAE [PR108282] Patrick Palka
@ 2023-01-04 19:05 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-01-04 19:05 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 1/4/23 11:37, Patrick Palka wrote:
> We typically ignore mark_used failure when in a non-SFINAE context for
> sake of better error recovery.  But in mark_single_function we're
> instead ignoring mark_used failure in a SFINAE context, which ends up
> causing the second static_assert here to incorrectly fail.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/12?

OK.

> 	PR c++/108282
> 
> gcc/cp/ChangeLog:
> 
> 	* decl2.cc (mark_single_function): Ignore mark_used failure
> 	only in a non-SFINAE context rather than in a SFINAE one.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-requires34.C: New test.
> ---
>   gcc/cp/decl2.cc                               |  2 +-
>   .../g++.dg/cpp2a/concepts-requires34.C        | 19 +++++++++++++++++++
>   2 files changed, 20 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C
> 
> diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc
> index f95529a5c9a..00ed64d1691 100644
> --- a/gcc/cp/decl2.cc
> +++ b/gcc/cp/decl2.cc
> @@ -5600,7 +5600,7 @@ mark_single_function (tree expr, tsubst_flags_t complain)
>   
>     if (is_overloaded_fn (expr) == 1
>         && !mark_used (expr, complain)
> -      && (complain & tf_error))
> +      && !(complain & tf_error))
>       return false;
>     return true;
>   }
> diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C
> new file mode 100644
> index 00000000000..670a6dab31a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C
> @@ -0,0 +1,19 @@
> +// PR c++/108282
> +// { dg-do compile { target c++20 } }
> +
> +template<class T>
> +concept TEST = requires { T::TT; };
> +
> +struct C { };
> +
> +template<class AT>
> +struct B {
> +  static inline void TT() requires TEST<AT>;
> +};
> +
> +int main() {
> +  static_assert( !TEST<C> );
> +  static_assert( !TEST<B<C>> );
> +
> +  B<C>::TT();  // { dg-error "no match" }
> +}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-04 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 16:37 [PATCH] c++: mark_single_function and SFINAE [PR108282] Patrick Palka
2023-01-04 19:05 ` Jason Merrill

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).