This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ PATCH] [PR13957] Improve diagnostic for missing typename


Gabriel Dos Reis wrote:

> With the changes, it is OK for mainline.  You'll need Mark's approval
> for 3_4 (but I would strongly recommend it).

OK, thanks for the quick review, this is what I eventually committed. Mark?

Giovanni Bajo


cp/
2004-02-01  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/13957
        * pt.c (tsubst_qualified_id): Improved error message when a type
        is expected but not found.

testsuite/
2004-02-01  Giovanni Bajo  <giovannibajo@gcc.gnu.org>

        PR c++/13957
        * g++.dg/template/non-type-template-argument-1.C,
        g++.dg/template/qualified-id1.C: Update dg-error marks.
        * g++.dg/template/nontype6.C: New test.


Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.818
diff -c -3 -p -r1.818 pt.c
*** cp/pt.c 19 Jan 2004 20:33:21 -0000 1.818
--- cp/pt.c 2 Feb 2004 01:02:17 -0000
*************** tsubst_qualified_id (tree qualified_id,
*** 7228,7235 ****
         ? DECL_TEMPLATE_RESULT (expr) : expr) == TYPE_DECL)
   {
     if (complain & tf_error)
!      error ("`%E' names a type, but a non-type is expected",
!      qualified_id);
     return error_mark_node;
   }
      }
--- 7228,7238 ----
         ? DECL_TEMPLATE_RESULT (expr) : expr) == TYPE_DECL)
   {
     if (complain & tf_error)
!      {
!        error ("dependent-name`%E' is parsed as a non-type, but "
!        "instantiation yields a type", qualified_id);
!        inform ("say `typename %E' if a type is meant", qualified_id);
!      }
     return error_mark_node;
   }
      }
Index: testsuite/g++.dg/template/non-type-template-argument-1.C
===================================================================
RCS file:
/cvs/gcc/gcc/gcc/testsuite/g++.dg/template/non-type-template-argument-1.C,v
retrieving revision 1.2
diff -c -3 -p -r1.2 non-type-template-argument-1.C
*** testsuite/g++.dg/template/non-type-template-argument-1.C 6 Sep 2003
11:29:17 -0000 1.2
--- testsuite/g++.dg/template/non-type-template-argument-1.C 2 Feb 2004
01:02:17 -0000
*************** template <bool> struct C {};
*** 6,12 ****

  template <typename T> struct D
  {
!    C<T::X> c;                   // { dg-error "names a type" }
  };

! D<B> d;                         // { dg-error "" }
--- 6,12 ----

  template <typename T> struct D
  {
!    C<T::X> c;                   // { dg-error "parsed as a non-type|if a type
is meant" }
  };

! D<B> d;                         // { dg-error "instantiated from here" }
Index: testsuite/g++.dg/template/qualified-id1.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.dg/template/qualified-id1.C,v
retrieving revision 1.1
diff -c -3 -p -r1.1 qualified-id1.C
*** testsuite/g++.dg/template/qualified-id1.C 5 Sep 2003 08:38:44 -0000 1.1
--- testsuite/g++.dg/template/qualified-id1.C 2 Feb 2004 01:02:17 -0000
*************** template <> struct A::B<false> {};
*** 16,23 ****

  template <typename T> void foo()
  {
!   T::C (); // { dg-error "names a type" "" }
!   T::template B<false>(); // { dg-error "names a type" "" }
  }

  void bar()
--- 16,23 ----

  template <typename T> void foo()
  {
!   T::C (); // { dg-error "parsed as a non-type|if a type is meant" "" }
!   T::template B<false>(); // { dg-error "parsed as a non-type|if a type is
meant" "" }
  }

  void bar()


// { dg-do compile }
// Origin: <v dot haisman at sh dot cvut dot cz>
// PR c++/13957: Improved error message for type in template (when non-type
//  is expected).

template <class T>
struct A
{
  typedef int type;
};

template <class T>
void func(void)
{
  (void)A<T>::type();  // { dg-error "if a type is meant" }
// { dg-error "parsed as a non-type" "" { target *-*-* } 15 }
}

template void func<float>(void);    // { dg-error "instantiated from here" }



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]