GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 19883 - [4.0 regression] Even more array bounds rejected as non-constant in template...
Summary: [4.0 regression] Even more array bounds rejected as non-constant in template...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Mark Mitchell
URL:
Keywords: monitored, rejects-valid
Depends on:
Blocks:
 
Reported: 2005-02-10 22:13 UTC by Volker Reichelt
Modified: 2005-02-22 21:47 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-10 23:16:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2005-02-10 22:13:13 UTC
The following valid code snippet is rejected by mainline:

====================================
template<typename T> struct A
{
    static const T i = 1;
    char a[int(i)];
};
====================================

The error message is:
  bug1.cc:4: error: array bound is not an integer constant


Mark, this is similar to PR19826 which you already fixed, but with an
additional cast.

For the same reason the following testcase fails, too:

==================================
template<int> struct A {};

template<typename T> struct B
{
    static const T i = 2;
    A<int(i)> a;
};
==================================

bug2.cc:6: error: template argument 1 is invalid

Due to this problem the testcase in PR19297 still fails on mainline.
Comment 1 Andrew Pinski 2005-02-10 23:16:13 UTC
Confirmed.
Comment 2 bredelin 2005-02-17 16:45:14 UTC
Note that this bug breaks BOOST.

Here is a reduced testcase, which comes from boost/mpl/aux_/integral_wrapper.hpp:

------------------ begin testcase
template< typename T, T N >
struct integral_c
{
  static const T value = N;

  typedef integral_c< T, static_cast<T>((value + 1)) > next;
  //  typedef integral_c< T, static_cast<T>((value - 1)) > prior;

  //  operator T() const { return static_cast<T>(this->value); }
};
------------------- end testcase 
% g++-cvs testcase.C
c.C:6: error: template argument 2 is invalid


The original error was obtained by including <boost/numeric/ublas/matrix.hpp>
The following error was recieved:

In file included from /usr/include/boost/config.hpp:35,
                 from /usr/include/boost/numeric/ublas/config.hpp:24,
                 from /usr/include/boost/numeric/ublas/matrix.hpp:20,
                 from a.C:1:
/usr/include/boost/config/compiler/gcc.hpp:92:7: warning: #warning "Unknown
compiler version - please run the configure tests and report the results"
/usr/include/boost/mpl/aux_/integral_wrapper.hpp:72: error: template argument 2
is invalid
/usr/include/boost/mpl/aux_/integral_wrapper.hpp:73: error: template argument 2
is invalid



Comment 3 Mark Mitchell 2005-02-22 21:47:36 UTC
Fixed in 4.0.