compile error with Boost Function object and templated function (Intel C++ compiler)

Discussion in 'C++' started by Faheem Mitha, Aug 26, 2006.

  1. Faheem Mitha

    Faheem Mitha Guest

    Hi,

    The following bit of code compiles fine with gcc 3.3 or later, but has
    problems with the Intel C++ compiler version 9.1, which produces the
    following error message.

    Is this a compiler bug, or is there something wrong with the code?

    If the former, I'd be grateful for suggestions of a workaround, and if
    the latter, please tell me what I'm doing wrong.

    Note that the corresponding version with no templates compiles without
    problems.

    Thanks in advance. Faheem.

    **************************************************************************

    icpc -o foo.o -c -Wall -Werror -g -wd383,810,981,1418 cxxlib-icc
    -DBOOST_RAND -I/usr/local/include/boost-1_33_1 \foo.cpp

    foo.cpp(12): error: no operator "=" matches these operands operand
    types are: boost::function<int (), std::allocator<void>> =
    <unknown-type>
    choice = &rchoice<dim>;
    ^
    *************************************************************
    #include <boost/function.hpp>

    template<int dim>
    int rchoice()
    {
    return 1;
    }

    template<int dim> int foo(void)
    {
    boost::function<int ()> choice;
    choice = &rchoice<dim>;
    return choice();
    }

    int main()
    {
    return foo<2>();
    }
    ***************************************************************
     
    Faheem Mitha, Aug 26, 2006
    #1
    1. Advertising

  2. Faheem Mitha

    mlimber Guest

    Faheem Mitha wrote:
    > Hi,
    >
    > The following bit of code compiles fine with gcc 3.3 or later, but has
    > problems with the Intel C++ compiler version 9.1, which produces the
    > following error message.
    >
    > Is this a compiler bug, or is there something wrong with the code?
    >
    > If the former, I'd be grateful for suggestions of a workaround, and if
    > the latter, please tell me what I'm doing wrong.
    >
    > Note that the corresponding version with no templates compiles without
    > problems.
    >
    > Thanks in advance. Faheem.
    >
    > **************************************************************************
    >
    > icpc -o foo.o -c -Wall -Werror -g -wd383,810,981,1418 cxxlib-icc
    > -DBOOST_RAND -I/usr/local/include/boost-1_33_1 \foo.cpp
    >
    > foo.cpp(12): error: no operator "=" matches these operands operand
    > types are: boost::function<int (), std::allocator<void>> =
    > <unknown-type>
    > choice = &rchoice<dim>;
    > ^
    > *************************************************************
    > #include <boost/function.hpp>
    >
    > template<int dim>
    > int rchoice()
    > {
    > return 1;
    > }
    >
    > template<int dim> int foo(void)
    > {
    > boost::function<int ()> choice;
    > choice = &rchoice<dim>;
    > return choice();
    > }
    >
    > int main()
    > {
    > return foo<2>();
    > }
    > ***************************************************************


    Changing the header to <functional> and boost::function to
    std::tr1::function, the code compiles fine at Dinkum's online test with
    both MS VC++8 and EDG, so I'd say it's an Intel problem. In that case,
    you'll want to post to a compiler-specific newsgroup or forum (in your
    case, something to do with Intel's compiler) for a work-around (see
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.9).

    Cheers! --M
     
    mlimber, Aug 26, 2006
    #2
    1. Advertising

  3. Faheem Mitha

    Faheem Mitha Guest

    On 26 Aug 2006 10:11:03 -0700, mlimber <> wrote:

    > Changing the header to <functional> and boost::function to
    > std::tr1::function, the code compiles fine at Dinkum's online test
    > with both MS VC++8 and EDG, so I'd say it's an Intel problem. In
    > that case, you'll want to post to a compiler-specific newsgroup or
    > forum (in your case, something to do with Intel's compiler) for a
    > work-around (see
    > http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.9).


    Thanks for the information. I don't quite get the bit about changing
    the header and boost::function, but if it is really a compiler bug,
    that is unfortunate.

    Faheem.
     
    Faheem Mitha, Aug 26, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lars Schouw
    Replies:
    5
    Views:
    2,878
    Jonathan Turkanis
    Aug 17, 2004
  2. Replies:
    0
    Views:
    323
  3. Amadeus W. M.
    Replies:
    2
    Views:
    414
    Amadeus W. M.
    Jul 4, 2006
  4. whatnext
    Replies:
    9
    Views:
    447
  5. Kazik�
    Replies:
    4
    Views:
    1,402
    Jonathan Lee
    Jul 6, 2009
Loading...

Share This Page