This is the mail archive of the gcc-bugs@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++/10273: g++ fails to compile sort() with a template operatorthat takes a pointer


> >   x.cc: In function `void std::doit()':
> >   x.cc:31: type/value mismatch at argument 1 in template parameter list for `
> >    template<std::ClassName*<anonymous> > struct std::xLess'
> >   x.cc:31:   expected a constant of type `std::ClassName*', got `std::ClassName*'
> >
> > I think the message says it quite clearly: first the type/value mismatch,
> > then in addition that it expected a value and got a type. What more do you
> > want?
> 
> Ok, so you know how to parse that message better than I do.  To me it says
> "expected type 'A', got 'A'" (where A is "std::ClassName*") and hence it
> does not make any sense to me. 

No, read it, it says
    expected a constant [i.e. a value] of type 'X', got 'X' [which is a type]

The situation is the same as if you had written
    template <int N> class X{};
and then used it as
    X<int> x;
That won't work.


> I'm the programmer, so because I don't
> intend for there to be a value there, I don't see a value there. 

If you intend there to be a type, then you should declare the template as 
taking a type, rather than a value.


> The error
> doesn't tell me that using * implies a value is being used in a template
> where a type should be.

What you wrote was 
    template <class ClassName *>  struct X {};
which, since ClassName is the name of an existing class, is equivalent to
    template <ClassName *> struct X {};
(that is just the same as declaring variables as  "struct X x;" or "X x;"
is equivalent in C++.)


> Just for the sake of comparison, I tried compiling the same piece of code
> with Visual Studio .Net and SUNWspro CC.  Both of those compilers (rightly
> or wrongly, I don't know) complain about the code when it comes to parsing
> the template statement.  In my situation, this type of verbosity helps.
> [...verbosity of other compilers deleted...]

These compilers simply don't realize that
    template <class C *> struct X {};
and
    template <C *>

W.

-------------------------------------------------------------------------
Wolfgang Bangerth             email:            bangerth at ticam dot utexas dot edu
                              www: http://www.ticam.utexas.edu/~bangerth/



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