Can anyone explain why the following C ++ code does not work as expected:
struct Object { template< int i > void foo(){ } }; template<int counter> struct Container { Object v[counter]; void test(){
The code above compiles without a flag. If one of the BUG1 flags is set to BUG3, compilation fails with GCC 4.6 or 4.7 and with clang 3.2 (which seems to indicate that this is not a GCC error).
Lines 21 through 29 do the same thing semantically (i.e., calling the method of the first element of the Object array), but only the latest version is compiled. The problem only occurs when trying to call a template method from a template object.
BUG1 is just a โnormalโ way to record a call.
BUG2 is the same thing, but access to the array is protected by brackets in case there is a problem with priority (but they should not be).
BUG3 shows that type inference also does not work (it must be compiled with C ++ 11 support).
The latest version works fine, but I donโt understand why using a temporary variable to store help solves the problem.
I am curious to know why the other three are invalid.
thanks
source share