c++/9285: REGRESSION: False shadowing of parameters in templates

wlandry@ucsd.edu wlandry@ucsd.edu
Mon Jan 13 05:17:00 GMT 2003


>Number:         9285
>Category:       c++
>Synopsis:       REGRESSION: False shadowing of parameters in templates
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 12 12:36:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     wlandry@ucsd.edu
>Release:        g++ (GCC) 3.4 20030110 (experimental)
>Organization:
>Environment:
i386 Linux
>Description:
I think this is a compiler bug.  I've attached test code
to the end of this message.  I get the error

foo.C: In constructor `Tensor1<T, Dim>::Tensor1(T, T)':
foo.C:24: error: declaration of `d0' shadows a parameter
foo.C:24: error: expected init-declarator
foo.C:24: error: expected `,' or `;'

It looks like the parser is just getting confused,
since there is no parameter to be shadowed.  What is
interesting is if I create a named variable in the
troublesome line

    Tensor1_constructor<T,Tensor_Dim> foo(data,d0,d1);

then it compiles fine.  Changing it to

    typename Tensor1_constructor<T,Tensor_Dim>(data,d0,d1);

still gives the error.  This works fine with 3.2, so
it is definitely a regression. Apparently it also worked
fine a little while ago (maybe Jan 1?).  FYI, This test
case was extracted from the FTensor test suite.  The
current version of FTensor won't compile with CVS HEAD
because of implicit typename problems, but there is a new
version that should work fine.

----------------------------------

template <class T, int Dim> class Tensor1;

template<class T, int Tensor_Dim>
class Tensor1_constructor;

template<class T>
class Tensor1_constructor<T,2>
{
public:
  Tensor1_constructor(T data[], T d0, T d1)
  {
    data[0]=d0;
    data[1]=d1;
  }
};

template <class T, int Tensor_Dim>
class Tensor1
{
  T data[Tensor_Dim];
public:
  Tensor1(T d0, T d1)
  {
    Tensor1_constructor<T,Tensor_Dim>(data,d0,d1);
  }
};
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list