]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: handle decltype in nested-name-spec printing [PR118139]
authorMarek Polacek <polacek@redhat.com>
Thu, 19 Dec 2024 22:47:03 +0000 (17:47 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 15 Jan 2025 15:02:13 +0000 (10:02 -0500)
Compiling this test, we emit:

  error: 'static void CW<T>::operator=(int) requires requires(typename'decltype_type' not supported by pp_cxx_unqualified_id::type x) {x;}' must be a non-static member function

where the DECLTYPE_TYPE isn't printed properly.  This patch fixes that
to print:

error: 'static void CW<T>::operator=(int) requires requires(typename decltype(T())::type x) {x;}' must be a non-static member function

PR c++/118139

gcc/cp/ChangeLog:

* cxx-pretty-print.cc (pp_cxx_nested_name_specifier): Handle
a computed-type-specifier.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/decltype1.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cxx-pretty-print.cc
gcc/testsuite/g++.dg/diagnostic/decltype1.C [new file with mode: 0644]

index 07439993e0b03c8aefb1657bb44b1cad278f6f33..cf301bd7cb32413dd5d6d1371974487a83441699 100644 (file)
@@ -234,8 +234,12 @@ pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
 }
 
 /* nested-name-specifier:
-      class-or-namespace-name :: nested-name-specifier(opt)
-      class-or-namespace-name :: template nested-name-specifier   */
+      ::
+      type-name ::
+      namespace-name ::
+      computed-type-specifier ::
+      nested-name-specifier identifier ::
+      nested-name-specifier template(opt) simple-template-id ::  */
 
 static void
 pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
@@ -252,7 +256,11 @@ pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
       tree scope = get_containing_scope (t);
       pp_cxx_nested_name_specifier (pp, scope);
       pp_cxx_template_keyword_if_needed (pp, scope, t);
-      pp_cxx_unqualified_id (pp, t);
+      /* This is a computed-type-specifier.  */
+      if (TREE_CODE (t) == PACK_INDEX_TYPE || TREE_CODE (t) == DECLTYPE_TYPE)
+       pp->type_id (t);
+      else
+       pp_cxx_unqualified_id (pp, t);
       pp_cxx_colon_colon (pp);
     }
 }
diff --git a/gcc/testsuite/g++.dg/diagnostic/decltype1.C b/gcc/testsuite/g++.dg/diagnostic/decltype1.C
new file mode 100644 (file)
index 0000000..8b57b16
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/118139
+// { dg-do compile { target c++20 } }
+
+template<class T>
+struct CW {
+  using V = typename decltype(T())::type;
+  static void operator=(int) requires requires(V x) { x; } {} // { dg-error {requires requires\(typename decltype\(T\(\)\)::type x\)} }
+};