This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH for c++/67012, c++/86942, detect invalid cases with function return type deduction
On Tue, Aug 21, 2018 at 11:59:06PM +1200, Jason Merrill wrote:
> On Fri, Aug 17, 2018 at 2:17 PM, Marek Polacek <polacek@redhat.com> wrote:
> > As I promised in <https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00908.html>,
> > this patch fixes a couple of invalid cases we weren't detecting. It's got
> > testcases from two PRs and another case I found out; they're intertwined so
> > I think it makes sense to fix them in one go.
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >
> > 2018-08-16 Marek Polacek <polacek@redhat.com>
> >
> > PR c++/86942
> > PR c++/67012
> > * decl.c (grokdeclarator): Disallow functions with trailing return
> > type with decltype(auto) as its type. Also check the function if
> > it's inner declarator doesn't exist.
> >
> > * g++.dg/cpp0x/auto52.C: New test.
> > * g++.dg/cpp1y/auto-fn52.C: New test.
> > * g++.dg/cpp1y/auto-fn53.C: New test.
> > * g++.dg/cpp1y/auto-fn54.C: New test.
> >
> > diff --git gcc/cp/decl.c gcc/cp/decl.c
> > index fa58bc4d2b3..8261f8e30e5 100644
> > --- gcc/cp/decl.c
> > +++ gcc/cp/decl.c
> > @@ -11238,7 +11238,10 @@ grokdeclarator (const cp_declarator *declarator,
> >
> > /* Handle a late-specified return type. */
> > tree late_return_type = declarator->u.function.late_return_type;
> > - if (funcdecl_p)
> > + if (funcdecl_p
> > + /* This is the case e.g. for
> > + using T = auto () -> int. */
> > + || inner_declarator == NULL)
>
> Hmm, checking funcdecl_p here seems just wrong; these errors should be
> the same regardless of whether this is declaring a function. What
> breaks if we just remove this condition? The deduction guide errors
> will need to be adjusted to handle the abstract declarator case, but
> that looks like the only spot that would need fixing.
That was my first idea but it breaks with pointers to functions and pointers
to member functions as in auto2.C:
auto (*fp)() = f;
where the declarators are: cdk_function -> cdk_pointer -> cdk_id
auto (A::*pmf)() = &A::f;
where the declarators are: cdk_function -> cdk_ptrmem -> cdk_id
it complains that a function uses 'auto' type specifier without trailing return type
> > {
> > if (tree auto_node = type_uses_auto (type))
> > {
> > @@ -11270,6 +11273,18 @@ grokdeclarator (const cp_declarator *declarator,
> > name, type);
> > return error_mark_node;
> > }
> > + else if (is_auto (type)
> > + && (TYPE_IDENTIFIER (type)
> > + == decltype_auto_identifier))
>
> I think you want AUTO_IS_DECLTYPE here.
Ah, nice.
Marek