[PR c++/84789] do not fail to resolve typename into template-independent
commit5904d9d923bd86849209e55550b7876e513f4896
authorAlexandre Oliva <aoliva@redhat.com>
Fri, 23 Mar 2018 01:19:14 +0000 (23 01:19 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Fri, 23 Mar 2018 01:19:14 +0000 (23 01:19 +0000)
treea8f986c5da0ff2a8e3e7afaf7e13d4dadd64afdc
parent3ec16e36107214035fe9d1177e0acc6ebe037112
[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.

From-SVN: r258792
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/dtor11.C
gcc/testsuite/g++.dg/template/pr84789-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/pr84789-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/pr84789.C [new file with mode: 0644]