problem with non-type template parameters (names) (+ patch)

Mark Mitchell mmitchell@usa.net
Fri Jan 30 07:04:00 GMT 1998


    hi -

    However, i ran into another template problem.
    For the following source, egcs (with Mark's patches) produces the errors:

    y.cc:11: object `yy' cannot be used as template argument
    y.cc:11: warning: ANSI C++ forbids declaration `zz' with no type

    ---------------------------------------------------------------------------
    template <const char* name>
    class x
    {
    };


    extern const char yy[];

    x<yy> zz;
    ---------------------------------------------------------------------------

    This sort of construct worked as of a couple snapshots ago.

    Looking at convert_nontype_argument(), i saw the following test which
    looked fishy:

      else if (TREE_CODE (expr_type) == VAR_DECL)

    since i'd think it's the _expression_, not the _type_, which is the
    variable reference.

Good spotting.  Your fix is correct.  I wrote the function
convert_nontype_argument a little while back since the previous g++
handling of nontype arguments was bogus with respect to the standard,
but, unfortunately, I don't always write perfect code on the first
try.  :-(

    Anyway, i tried the following change, which seemed to fix the problem.

    thanks,
    sss


    1998-01-30  scott snyder  <snyder@d0sgif.fnal.gov>

	    * pt.c (convert_nontype_argument): Test EXPR for VAR_DECL, not
	    EXPR_TYPE.


    *** pt.c-orig   Fri Jan 30 00:16:47 1998
    --- pt.c        Fri Jan 30 00:24:56 1998
    ***************
    *** 1480,1486 ****
	      return error_mark_node;
	    }
	  }
    !   else if (TREE_CODE (expr_type) == VAR_DECL)
	  {
	    if (!TREE_PUBLIC (expr))
	    goto bad_argument;
    --- 1480,1486 ----
	      return error_mark_node;
	    }
	  }
    !   else if (TREE_CODE (expr) == VAR_DECL)
	  {
	    if (!TREE_PUBLIC (expr))
	    goto bad_argument;


-- 
Mark Mitchell		mmitchell@usa.net
Stanford University	http://www.stanford.edu




More information about the Gcc-bugs mailing list