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 <ja...@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