/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 3 May 2013 09:02:15 +0000 (09:02 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 3 May 2013 09:02:15 +0000 (09:02 +0000)
2013-05-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/14283
* parser.c (cp_parser_diagnose_invalid_type_name): Improve error
messages for template types and fix column numbers.

/testsuite
2013-05-03  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/14283
* g++.dg/parse/error51.C: New.
* g++.dg/parse/error15.C: Adjust column numbers.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@198572 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/error15.C
gcc/testsuite/g++.dg/parse/error51.C [new file with mode: 0644]

index e4996fb..b9bdf3a 100644 (file)
@@ -1,3 +1,9 @@
+2013-05-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/14283
+       * parser.c (cp_parser_diagnose_invalid_type_name): Improve error
+       messages for template types and fix column numbers.
+
 2013-05-01  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/57132
index 2239a07..f87974e 100644 (file)
@@ -2872,8 +2872,16 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser,
   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 *parser,
                  "%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 c8dc189..88ac420 100644 (file)
@@ -1,3 +1,9 @@
+2013-05-03  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/14283
+       * g++.dg/parse/error51.C: New.
+       * g++.dg/parse/error15.C: Adjust column numbers.
+
 2013-05-02  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/57142
index 607a1db..deba54a 100644 (file)
@@ -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" }
 };
 
diff --git a/gcc/testsuite/g++.dg/parse/error51.C b/gcc/testsuite/g++.dg/parse/error51.C
new file mode 100644 (file)
index 0000000..e599304
--- /dev/null
@@ -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" }
+};