* [C++ PATCH] Avoid weird inform without previos error during SFINAE (PR c++/92965)
@ 2019-12-17 20:58 Jakub Jelinek
2019-12-20 23:22 ` Jason Merrill
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2019-12-17 20:58 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
On the following testcase, complain & tf_error is 0 during sfinae, so we
don't emit error, but we called structural_type_p with explain=true anyway,
which emitted the inform messages.
Fixed by doing it only when we emit the error.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
BTW, is the testcase valid in C++17 mode? GCC 7/8/9/trunk accept it,
but clang++ rejects it.
2019-12-17 Jakub Jelinek <jakub@redhat.com>
PR c++/92965
* pt.c (invalid_nontype_parm_type_p): Call structural_type_p with
explain=true only if emitting error.
* g++.dg/cpp2a/nontype-class27.C: New test.
--- gcc/cp/pt.c.jj 2019-12-11 18:19:03.188162534 +0100
+++ gcc/cp/pt.c 2019-12-17 14:21:48.903024760 +0100
@@ -25829,11 +25829,13 @@ invalid_nontype_parm_type_p (tree type,
return true;
if (!structural_type_p (type))
{
- auto_diagnostic_group d;
if (complain & tf_error)
- error ("%qT is not a valid type for a template non-type parameter "
- "because it is not structural", type);
- structural_type_p (type, true);
+ {
+ auto_diagnostic_group d;
+ error ("%qT is not a valid type for a template non-type "
+ "parameter because it is not structural", type);
+ structural_type_p (type, true);
+ }
return true;
}
return false;
--- gcc/testsuite/g++.dg/cpp2a/nontype-class27.C.jj 2019-12-17 14:35:42.339473136 +0100
+++ gcc/testsuite/g++.dg/cpp2a/nontype-class27.C 2019-12-17 14:26:13.461040058 +0100
@@ -0,0 +1,15 @@
+// PR c++/92965
+// { dg-do compile { target c++2a } }
+
+template<int>
+class TS {
+ int x; // { dg-bogus "is not public" }
+public:
+ constexpr TS(int) {}
+};
+TS(int) -> TS<1>;
+
+template<TS> void foo() {}
+template<int> void foo() {}
+
+void test() { foo<2>(); }
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C++ PATCH] Avoid weird inform without previos error during SFINAE (PR c++/92965)
2019-12-17 20:58 [C++ PATCH] Avoid weird inform without previos error during SFINAE (PR c++/92965) Jakub Jelinek
@ 2019-12-20 23:22 ` Jason Merrill
2019-12-21 0:14 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2019-12-20 23:22 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 12/17/19 3:51 PM, Jakub Jelinek wrote:
> Hi!
>
> On the following testcase, complain & tf_error is 0 during sfinae, so we
> don't emit error, but we called structural_type_p with explain=true anyway,
> which emitted the inform messages.
> Fixed by doing it only when we emit the error.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> BTW, is the testcase valid in C++17 mode? GCC 7/8/9/trunk accept it,
> but clang++ rejects it.
No, non-template parameters of class types are a C++20 feature.
> 2019-12-17 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/92965
> * pt.c (invalid_nontype_parm_type_p): Call structural_type_p with
> explain=true only if emitting error.
>
> * g++.dg/cpp2a/nontype-class27.C: New test.
>
> --- gcc/cp/pt.c.jj 2019-12-11 18:19:03.188162534 +0100
> +++ gcc/cp/pt.c 2019-12-17 14:21:48.903024760 +0100
> @@ -25829,11 +25829,13 @@ invalid_nontype_parm_type_p (tree type,
> return true;
> if (!structural_type_p (type))
> {
> - auto_diagnostic_group d;
> if (complain & tf_error)
> - error ("%qT is not a valid type for a template non-type parameter "
> - "because it is not structural", type);
> - structural_type_p (type, true);
> + {
> + auto_diagnostic_group d;
> + error ("%qT is not a valid type for a template non-type "
> + "parameter because it is not structural", type);
> + structural_type_p (type, true);
> + }
> return true;
> }
> return false;
> --- gcc/testsuite/g++.dg/cpp2a/nontype-class27.C.jj 2019-12-17 14:35:42.339473136 +0100
> +++ gcc/testsuite/g++.dg/cpp2a/nontype-class27.C 2019-12-17 14:26:13.461040058 +0100
> @@ -0,0 +1,15 @@
> +// PR c++/92965
> +// { dg-do compile { target c++2a } }
> +
> +template<int>
> +class TS {
> + int x; // { dg-bogus "is not public" }
> +public:
> + constexpr TS(int) {}
> +};
> +TS(int) -> TS<1>;
> +
> +template<TS> void foo() {}
> +template<int> void foo() {}
> +
> +void test() { foo<2>(); }
>
> Jakub
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C++ PATCH] Avoid weird inform without previos error during SFINAE (PR c++/92965)
2019-12-20 23:22 ` Jason Merrill
@ 2019-12-21 0:14 ` Jakub Jelinek
0 siblings, 0 replies; 3+ messages in thread
From: Jakub Jelinek @ 2019-12-21 0:14 UTC (permalink / raw)
To: Jason Merrill, Marek Polacek; +Cc: gcc-patches
On Fri, Dec 20, 2019 at 06:18:04PM -0500, Jason Merrill wrote:
> > BTW, is the testcase valid in C++17 mode? GCC 7/8/9/trunk accept it,
> > but clang++ rejects it.
>
> No, non-template parameters of class types are a C++20 feature.
Trunk accepts it since r276248 aka PR91923 in -std=c++17 mode.
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-21 0:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17 20:58 [C++ PATCH] Avoid weird inform without previos error during SFINAE (PR c++/92965) Jakub Jelinek
2019-12-20 23:22 ` Jason Merrill
2019-12-21 0:14 ` Jakub Jelinek
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).