Hi,
in this rather old diagnostic issue, we want to provide better error
messages, spelling out template if appropriate, and also fix the column
numbers (in practice location_of (id) boils down to input_location which
is the right position for this kind of error message among those handled
by cp_parser_diagnose_invalid_type_name). Tested x86_64-linux.
Thanks,
Paolo.
/////////////////////////////
/cp
2013-05-02 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/14283
* parser.c (cp_parser_diagnose_invalid_type_name): Improve error
messages for template types and fix column number.
/testsuite
2013-05-02 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/14283
* g++.dg/parse/error51.C: New.
* g++.dg/parse/error15.C: Adjust column numbers.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 198521)
+++ cp/parser.c (working copy)
@@ -2872,8 +2872,16 @@ cp_parser_diagnose_invalid_type_name (cp_parser *p
else if (parser->scope != error_mark_node)
{
if (TREE_CODE (parser->scope) == NAMESPACE_DECL)
- error_at (location, "%qE in namespace %qE does not name a type",
- id, parser->scope);
+ {
+ if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
+ error_at (location_of (id),
+ "%qE in namespace %qE does not name a template type",
+ id, parser->scope);
+ else
+ error_at (location_of (id),
+ "%qE in namespace %qE does not name a type",
+ id, parser->scope);
+ }
else if (CLASS_TYPE_P (parser->scope)
&& constructor_name_p (id, parser->scope))
{
@@ -2890,8 +2898,16 @@ cp_parser_diagnose_invalid_type_name (cp_parser *p
"%qT is a dependent scope",
parser->scope, id, parser->scope);
else if (TYPE_P (parser->scope))
- error_at (location, "%qE in %q#T does not name a type",
- id, parser->scope);
+ {
+ if (cp_lexer_next_token_is (parser->lexer, CPP_LESS))
+ error_at (location_of (id),
+ "%qE in %q#T does not name a template type",
+ id, parser->scope);
+ else
+ error_at (location_of (id),
+ "%qE in %q#T does not name a type",
+ id, parser->scope);
+ }
else
gcc_unreachable ();
}
Index: testsuite/g++.dg/parse/error15.C
===================================================================
--- testsuite/g++.dg/parse/error15.C (revision 198521)
+++ testsuite/g++.dg/parse/error15.C (working copy)
@@ -11,9 +11,9 @@ namespace N
}
N::A f2; // { dg-error "1:invalid use of template-name 'N::A'
without an argument list" }
-N::INVALID f3; // { dg-error "1:'INVALID' in namespace 'N' does not
name a type" }
-N::C::INVALID f4; // { dg-error "1:'INVALID' in 'struct N::C' does not
name a type" }
-N::K f6; // { dg-error "1:'K' in namespace 'N' does not name a
type" }
+N::INVALID f3; // { dg-error "4:'INVALID' in namespace 'N' does not
name a type" }
+N::C::INVALID f4; // { dg-error "7:'INVALID' in 'struct N::C' does not
name a type" }
+N::K f6; // { dg-error "4:'K' in namespace 'N' does not name a
type" }
typename N::A f7;
// { dg-error "13:invalid use of template-name 'N::A' without an argument
list" "13" { target *-*-* } 17 }
// { dg-error "17:invalid type in declaration before ';' token" "17" { target
*-*-* } 17 }
@@ -21,9 +21,9 @@ typename N::A f7;
struct B
{
N::A f2; // { dg-error "3:invalid use of template-name 'N::A'
without an argument list" }
- N::INVALID f3; // { dg-error "3:'INVALID' in namespace 'N' does not
name a type" }
- N::C::INVALID f4; // { dg-error "3:'INVALID' in 'struct N::C' does not
name a type" }
- N::K f6; // { dg-error "3:'K' in namespace 'N' does not name a
type" }
+ N::INVALID f3; // { dg-error "6:'INVALID' in namespace 'N' does not
name a type" }
+ N::C::INVALID f4; // { dg-error "9:'INVALID' in 'struct N::C' does not
name a type" }
+ N::K f6; // { dg-error "6:'K' in namespace 'N' does not name a
type" }
typename N::A f7;
// { dg-error "15:invalid use of template-name 'N::A' without an argument
list" "15" { target *-*-* } 27 }
};
@@ -32,9 +32,9 @@ template <int>
struct C
{
N::A f2; // { dg-error "3:invalid use of template-name 'N::A'
without an argument list" }
- N::INVALID f3; // { dg-error "3:'INVALID' in namespace 'N' does not
name a type" }
- N::C::INVALID f4; // { dg-error "3:'INVALID' in 'struct N::C' does not
name a type" }
- N::K f6; // { dg-error "3:'K' in namespace 'N' does not name a
type" }
+ N::INVALID f3; // { dg-error "6:'INVALID' in namespace 'N' does not
name a type" }
+ N::C::INVALID f4; // { dg-error "9:'INVALID' in 'struct N::C' does not
name a type" }
+ N::K f6; // { dg-error "6:'K' in namespace 'N' does not name a
type" }
typename N::A f7; // { dg-error "15:invalid use of template-name 'N::A'
without an argument list" }
};
Index: testsuite/g++.dg/parse/error51.C
===================================================================
--- testsuite/g++.dg/parse/error51.C (revision 0)
+++ testsuite/g++.dg/parse/error51.C (working copy)
@@ -0,0 +1,13 @@
+// PR c++/14283
+
+struct A
+{};
+
+namespace N
+{}
+
+template <typename> struct C
+{
+ typedef A::template INVALID<void> X0; // { dg-error "23:'INVALID' in
'struct A' does not name a template type" }
+ typedef N::template INVALID<void> X1; // { dg-error "23:'INVALID' in
namespace 'N' does not name a template type" }
+};