public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5682] c++: Give better placeholder diagnostic
@ 2020-12-02 21:15 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2020-12-02 21:15 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2847d7d28ea79e2f93049fad16f931b6705c9fff

commit r11-5682-g2847d7d28ea79e2f93049fad16f931b6705c9fff
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Nov 26 05:45:02 2020 -0500

    c++: Give better placeholder diagnostic
    
    We were saying 'auto parameter not permitted' in a place where 'auto' is in
    fact permitted in C++20, but a class template placeholder is not.
    
    gcc/cp/ChangeLog:
    
            * decl.c (grokdeclarator): Improve diagnostic for
            disallowed CTAD placeholder.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/other/pr88187.C: Adjust expected error.
            * g++.dg/cpp2a/class-deduction-abbrev1.C: New test.

Diff:
---
 gcc/cp/decl.c                                        | 10 ++++++++++
 gcc/testsuite/g++.dg/cpp2a/class-deduction-abbrev1.C | 13 +++++++++++++
 gcc/testsuite/g++.dg/other/pr88187.C                 |  2 +-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1e2bae4afba..0cf84a0750c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13145,6 +13145,16 @@ grokdeclarator (const cp_declarator *declarator,
 	      if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
 		error_at (typespec_loc,
 			  "cannot declare a parameter with %<decltype(auto)%>");
+	      else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
+		{
+		  auto_diagnostic_group g;
+		  error_at (typespec_loc,
+			    "class template placeholder %qE not permitted "
+			    "in this context", c);
+		  if (decl_context == PARM && cxx_dialect >= cxx20)
+		    inform (typespec_loc, "use %<auto%> for an "
+			    "abbreviated function template");
+		}
 	      else
 		error_at (typespec_loc,
 			  "%<auto%> parameter not permitted in this context");
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-abbrev1.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-abbrev1.C
new file mode 100644
index 00000000000..f9310090b5b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-abbrev1.C
@@ -0,0 +1,13 @@
+ // { dg-do compile { target c++20 } }
+
+template <class T> struct A { };
+template <class T> concept is_A = requires { A(T()); };
+
+void f(auto);      // OK
+void f(is_A auto); // OK
+void f(A);	   // { dg-error "placeholder" }
+
+int main()
+{
+  f(A<int>());
+}
diff --git a/gcc/testsuite/g++.dg/other/pr88187.C b/gcc/testsuite/g++.dg/other/pr88187.C
index ebdafddc634..13466d3ce57 100644
--- a/gcc/testsuite/g++.dg/other/pr88187.C
+++ b/gcc/testsuite/g++.dg/other/pr88187.C
@@ -4,4 +4,4 @@
 template <int> struct A;
 void f (A ());	// { dg-error "6:variable or field 'f' declared void" "" { target c++14_down } }
 		// { dg-error "missing template arguments before '\\(' token" "" { target c++14_down } .-1 }
-		// { dg-error "'auto' parameter not permitted in this context" "" { target c++17 } .-2 }
+		// { dg-error "placeholder .A. not permitted in this context" "" { target c++17 } .-2 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-02 21:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-02 21:15 [gcc r11-5682] c++: Give better placeholder diagnostic 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).