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

--- Comment #6 from Alexandre Oliva <aoliva at gcc dot gnu.org> ---
Author: aoliva
Date: Fri Mar 23 01:19:14 2018
New Revision: 258792

URL: https://gcc.gnu.org/viewcvs?rev=258792&root=gcc&view=rev
Log:
[PR c++/84789] do not fail to resolve typename into template-independent

Although resolve_typename_type always takes a template-dependent
type-id, and it usually resolves it to another template-dependent
type-id, it is not correct to require the latter: in declarators,
template-dependent scopes may turn out to name template-independent
types, as in the pr84789-2.C and pr84789-3.C testcases.

The ill-formed testcase pr84789.C trips the same too-strict assert,
and also gets fixed by removing the assertion on the simplified scope.
However, whereas when the dependent type cannot be resolved, we get an
error that suggests 'typename' is missing:

pr84789.C:12:3: error: need ‘typename’ before ‘typename B<T>::A::I::I’
because ‘typename B<T>::A::I’ is a dependent scope
   B<T>::A::I::I i;
   ^~~~

when it can, we got errors that did not point at that possibility,
which may be confusing:

pr84789.C:9:15: error: ‘A::I’ {aka ‘int’} is not a class type
   B<T>::A::I::I i; // { dg-error "typename" }
               ^
pr84789.C:9:15: error: ‘I’ in ‘A::I’ {aka ‘int’} does not name a type

Changing the parser diagnostic code that reports an invalid type name
so that it does not attempt to reparse the name as a declarator gets
us the superior diagnostic of a missing 'typename' keyword.


for  gcc/cp/ChangeLog

        PR c++/84789
        * pt.c (resolve_typename_type): Drop assert that stopped
        simplification to template-independent types.  Add assert to
        verify the initial scope is template dependent.
        * parser.c (cp_parser_parse_and_diagnose_invalid_type_name):
        Reparse the id expression as a type-name, not a declarator.

for  gcc/testsuite/ChangeLog

        PR c++/84789
        * g++.dg/template/pr84789.C: New.
        * g++.dg/template/pr84789-2.C: New.
        * g++.dg/template/pr84789-3.C: New.
        * g++.dg/parse/dtor11.C: Accept alternate error message.

Added:
    trunk/gcc/testsuite/g++.dg/template/pr84789-2.C
    trunk/gcc/testsuite/g++.dg/template/pr84789-3.C
    trunk/gcc/testsuite/g++.dg/template/pr84789.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/parse/dtor11.C

Reply via email to