https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51851

--- Comment #7 from qingzhe huang <nickhuang99 at hotmail dot com> ---
Thank you for clarifications!

I just found a solution for this 10-year-old issue and preparing a patch.
However, the solution is not able to solve more complicated cases which
requires more work.
This issue is so complicated and I am hesitating to file more complicated bugs
which this patch won't work because it requires improvement work of function
*resolve_typename_type* to handle recursive case correctly.



diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3414cbdc876..db0d43b2b08 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14493,7 +14493,16 @@ grokparms (tree parmlist, tree *parms)

          /* Top-level qualifiers on the parameters are
             ignored for function types.  */
-         type = cp_build_qualified_type (type, 0);
+         int type_quals = 0;
+         /* Top-level qualifiers are reserved for array type. PR101783 */
+         if (TREE_CODE (type) == TYPENAME_TYPE)
+         {
+            tree resolved_type = resolve_typename_type(type, false);
+            if (resolved_type && TREE_CODE(resolved_type) == ARRAY_TYPE)
+               type_quals = CP_TYPE_CONST_P(type);
+         }
+         type = cp_build_qualified_type (type, type_quals);
+
          if (TREE_CODE (type) == METHOD_TYPE)
            {
              error ("parameter %qD invalidly declared method type", decl);

Reply via email to