Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ static template function causes armcc compilation error (304)

I have tested compilation of the following code on both VS10 and armcc4.1 [Build 561]. Both functions depth1() and depth2() compile on VS, however armcc will only compile depth1() while giving an Error 304 (no instance of matches the argument list) for depth2(). When foo and bar are non-static, it compiles fine on armcc as well.

I'd be happy to understand why.

template <class T>
static T foo(T arg)
{
   return arg*5;
}

template <class T>
static T bar(T arg)
{
   return foo<T>(arg);
}

void depth2()
{
   int i = 12;
   i = bar<int>(i);
}

void depth1()
{
   int i = 12;
   i = foo<int>(i);
}
like image 675
levengli Avatar asked Oct 21 '22 10:10

levengli


1 Answers

Per the comments above: This appears to be a bug in armcc 4.1.

If your employer has a support contract with ARM, you can raise a support issue with ARM here: http://www.arm.com/support/obtaining-support/index.php (click the "Development Tools" tab and then the big blue "Raise a Support Case" button).

As for workarounds, you might try

  • rearranging the definitions of foo and bar in the source file; and/or
  • providing a forward declaration for foo and/or bar somewhere prior to its definition; and/or
  • adding an explicit instantiation of foo<int> somewhere after its declaration, like this:

    template int foo(int arg);
    // or, if you like this style better,
    template int foo<int>(int arg);
    
like image 71
Quuxplusone Avatar answered Nov 15 '22 04:11

Quuxplusone