In 46245, we were complaining too soon about an auto parameter; we need
to wait until after we splice in a late-specified return type. In
46145, we were failing to complain about an auto typedef.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 0ca632627d749d168b602675ca48df9e88a1eac5
Author: Jason Merrill <ja...@redhat.com>
Date: Wed May 25 13:03:13 2011 -0400
PR c++/46145
* decl.c (grokdeclarator): Complain about auto typedef.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 68dc999..db52184 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9503,6 +9503,12 @@ grokdeclarator (const cp_declarator *declarator,
memfn_quals = TYPE_UNQUALIFIED;
}
+ if (type_uses_auto (type))
+ {
+ error ("typedef declared %<auto%>");
+ type = error_mark_node;
+ }
+
if (decl_context == FIELD)
decl = build_lang_decl (TYPE_DECL, unqualified_id, type);
else
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto9.C b/gcc/testsuite/g++.dg/cpp0x/auto9.C
index 142ef90..190bfa6 100644
--- a/gcc/testsuite/g++.dg/cpp0x/auto9.C
+++ b/gcc/testsuite/g++.dg/cpp0x/auto9.C
@@ -119,3 +119,6 @@ H<auto> h; // { dg-error "invalid" }
void qq (auto); // { dg-error "auto" }
void qr (auto*); // { dg-error "auto" }
+
+// PR c++/46145
+typedef auto autot; // { dg-error "auto" }
commit 2ab4982d07fd89b0a7bc42868aa655173a132af7
Author: Jason Merrill <ja...@redhat.com>
Date: Wed May 25 12:22:13 2011 -0400
PR c++/46245
* decl.c (grokdeclarator): Complain later for auto parameter.
* pt.c (splice_late_return_type): Handle use in a template
type-parameter.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index cc09c1d..68dc999 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8763,12 +8763,6 @@ grokdeclarator (const cp_declarator *declarator,
|| thread_p)
error ("storage class specifiers invalid in parameter declarations");
- if (type_uses_auto (type))
- {
- error ("parameter declared %<auto%>");
- type = error_mark_node;
- }
-
/* Function parameters cannot be constexpr. If we saw one, moan
and pretend it wasn't there. */
if (constexpr_p)
@@ -9749,6 +9743,12 @@ grokdeclarator (const cp_declarator *declarator,
if (ctype || in_namespace)
error ("cannot use %<::%> in parameter declaration");
+ if (type_uses_auto (type))
+ {
+ error ("parameter declared %<auto%>");
+ type = error_mark_node;
+ }
+
/* A parameter declared as an array of T is really a pointer to T.
One declared as a function is really a pointer to a function.
One declared as a member is really a pointer to member. */
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index bb4515b..c3c759e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19315,7 +19315,12 @@ splice_late_return_type (tree type, tree late_return_type)
return type;
argvec = make_tree_vec (1);
TREE_VEC_ELT (argvec, 0) = late_return_type;
- if (processing_template_decl)
+ if (processing_template_parmlist)
+ /* For a late-specified return type in a template type-parameter, we
+ need to add a dummy argument level for its parmlist. */
+ argvec = add_to_template_args
+ (make_tree_vec (processing_template_parmlist), argvec);
+ if (current_template_parms)
argvec = add_to_template_args (current_template_args (), argvec);
return tsubst (type, argvec, tf_warning_or_error, NULL_TREE);
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto23.C b/gcc/testsuite/g++.dg/cpp0x/auto23.C
new file mode 100644
index 0000000..49b5a0e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto23.C
@@ -0,0 +1,4 @@
+// PR c++/46245
+// { dg-options -std=c++0x }
+
+template<auto f()->int> struct A { };
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto9.C b/gcc/testsuite/g++.dg/cpp0x/auto9.C
index ab90be5..142ef90 100644
--- a/gcc/testsuite/g++.dg/cpp0x/auto9.C
+++ b/gcc/testsuite/g++.dg/cpp0x/auto9.C
@@ -79,10 +79,10 @@ enum struct D : auto * { FF = 0 }; // { dg-error "must be an integral type|decl
void
bar ()
{
- try { } catch (auto i) { } // { dg-error "invalid use of" }
- try { } catch (auto) { } // { dg-error "invalid use of" }
- try { } catch (auto *i) { } // { dg-error "invalid use of" }
- try { } catch (auto *) { } // { dg-error "invalid use of" }
+ try { } catch (auto i) { } // { dg-error "parameter declared" }
+ try { } catch (auto) { } // { dg-error "parameter declared" }
+ try { } catch (auto *i) { } // { dg-error "parameter declared" }
+ try { } catch (auto *) { } // { dg-error "parameter declared" }
}
void