c++/3911: error with multiple non-type template parameters

smacdonald@seimac.com smacdonald@seimac.com
Wed Aug 1 10:56:00 GMT 2001


>Number:         3911
>Category:       c++
>Synopsis:       error with multiple non-type template parameters
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 01 10:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Scott MacDonald
>Release:        GCC 3.0
>Organization:
>Environment:
Red Hat Linux 6.2, Intel
>Description:

g++ seems to have a problem with more than one non-type template parameter, ints in this case.

The code works fine using g++ ( 2.95.2 on Redhat 6.2), aCC (3.27 on HP-UX 11.0), and Comeau C++ (4.2.45.2 online version).  As of Augest 1, 2001 it fails on Code Sourcery's nightly build test site (great idea by the way).

This was the results of a compile (error1.cc is below)
    > g++ error1.cc
    error1.cc: In function `int main()':
    error1.cc:21: non-constant `-0' cannot be used as template argument
    error1.cc:21: no match for `const unit<1, 0>& / const unit<2, 0>&' operator
template argument


In this example all of the template parameters are either literals or as a direct result of subtracting other template parameters.  None of the parameters should be non-constant.

As an interesting note if you only use one template parameter instead of two it compiles fine.  To see the results of this compile works.cc:
    > g++ works.cc

I hope this helps and I am looking forward to using the new release.

Scott MacDonald

CODE:

==============
error1.cc

 
template < int I1, int I2 >
class unit
{
public:
  unit() {}
  unit( const unit<I1,I2>& ) {}
 
  template< int Q1, int Q2 >
  unit< I1 - Q1, I2 - Q2 > operator / ( const unit< Q1, Q2 >& rhs ) const {
    return unit< I1 - Q1, I2 - Q2 >();
  }
 
};
 
int main()
{
  const unit<1,0> u1;
  const unit<2,0> u2;
 
  unit<-1,0> u3( u1 / u2 );
}

=================
works.cc

 
template < int I1 >
class unit
{
public:
  unit() {}
  unit( const unit<I1>& ) {}
 
  template< int Q1 >
  unit< I1 - Q1 > operator / ( const unit< Q1 >& rhs ) const {
    return unit< I1 - Q1 >();
  }
 
};
 
int main()
{
  const unit<1> u1;
  const unit<2> u2;
 
  unit<-1> u3( u1 / u2 );
}

>How-To-Repeat:
g++ error1.cc
>Fix:

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



More information about the Gcc-bugs mailing list