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++/6273: ...


This is the shortest testcase I can come up with:
-----------------
template<class S> class TableMap
{
public:
  enum { Index_max = 10 };
  int items[ Index_max + 1 ];
};

template<class T> T operator+ (const T& a, const int& b)
{
   return a ;
}

TableMap<int> CharDFS;

int main(void)
{
}
---------------

I get these errors from cc1plus:

T operator+(const T&, const int&)
/home/neroden/ice.cxx: At global scope:
/home/neroden/ice.cxx:13: error: variable-size type declared outside of any
   function
/home/neroden/ice.cxx:13: error: variable-size type declared outside of any
   function
 int main() int main() T operator+(const T&, const int&) [with T = 
TableMap<int>::<anonymous enum>

It requires that '+' be used in the length-of-array spec.  This is what 
triggers that 'variable-size type' complaint; the sum is matching the 
template definition of operator+ (between an anonymous enum and an integer) 
rather than the ordinary integer sum, and this is causing gcc to decide that 
it's not a constant.  I don't think it's reasonable to require GCC to realize 
that the definition of operator+ in fact generates a compile-time constant.

So, is this a non-bug, or should the sum *not* resolve to the defined version 
of operator+ ?

--
In the original testcase, the use of "+=" inside the definition of operator+ 
triggers another error:
/home/neroden/ice.cxx:5:   instantiated from `TableMap<int>'
/home/neroden/ice.cxx:14:   instantiated from here
/home/neroden/ice.cxx:11: error: no match for `TableMap<int>::<anonymous 
enum>&  += const int&' operator


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