This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/6273: ...
- From: Nathanael Nerode <neroden at twcny dot rr dot com>
- To: gcc-gnats at gcc dot gnu dot org, comer at mailru dot com, gcc-bugs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: Mon, 20 Jan 2003 00:21:52 -0500
- Subject: Re: c++/6273: ...
- Reply-to: neroden at twcny dot rr dot com
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