Expression Compiling Error under ICC 11.1

Expression Compiling Error under ICC 11.1

Аватар пользователя Zenny Chen
void Dummy(void)
{
    
}

template 
void lambdaTest(LAMBDA lam)
{
    auto result = ([](void) { return [](LAMBDA l) -> void { }; })();    // OK
    ([](LAMBDA l) -> void { l(); })(lam);    // OK
    ([&lam](void) -> void { lam(); })();    // OK
    
    void (*p)(void) = Dummy;
    ([p](void) { return [p](void) -> void { (*p)(); }; })()();    // OK
    
    ([&lam](void) { return [&lam](void) -> void { lam(); }; })();    // ERROR
    ([](LAMBDA l) { return [&l](void) -> void { l(); }; })(lam);    // ERROR
}


int main(void) 
{
    lambdaTest([](void)->void{});
}

The code above failed to compile under ICC 11.1 with an unkown error (compiling abort) for Mac OS X but compiled successfully under ICC 11.0.061 for Windows XP.

However, the following code can be compiled successfully:

#include 
using namespace std;

int main(void) 
{
    auto lam = [](void) -> void { cout << "I am !" << endl; };

    ([&lam](void) { return (cout << "I am a high-order function!" << endl, 
        [&lam](void) -> void { lam(); }); })()();
}

I wonder what has happend with ICC 11.1 about lambda expression.

18 сообщений / 0 новое
Последнее сообщение
Пожалуйста, обратитесь к странице Уведомление об оптимизации для более подробной информации относительно производительности и оптимизации в программных продуктах компании Intel.
Аватар пользователя Zenny Chen
The full version for Mac OS X I 'm using is 11.1.058.
Аватар пользователя Tim Prince

g++ zc.cpp
zc.cpp: In function void lambdaTest(LAMBDA):
zc.cpp:9:10: error: ISO C++ forbids declaration of result with no type
zc.cpp:9:20: error: expected primary-expression before [ token
zc.cpp:9:21: error: expected primary-expression before ] token
zc.cpp:9:23: error: expected primary-expression before void
zc.cpp:9:29: error: expected ) before { token
zc.cpp:24:1: error: expected , or ; at end of input
zc.cpp:24:1: error: expected } at end of input

icpc zc.cpp
zc.cpp(23): error: expected an expression
lambdaTest([](void)->void{});
^

zc.cpp(9): error #303: explicit type is missing ("int" assumed)
auto result = ([](void) { return [](LAMBDA l) -> void { }; })(); // OK
^
....

I can provoke an internal error by setting icpc -std=c++0x which I suppose would justify a bug report, but this doesn't appear to reproduce your finding. Short of that, g++ and icpc appear in basic agreement about the demerits of my copy of your case.

Аватар пользователя Zenny Chen
Quoting - tim18 g++ zc.cpp
zc.cpp: In function void lambdaTest(LAMBDA):
zc.cpp:9:10: error: ISO C++ forbids declaration of result with no type
zc.cpp:9:20: error: expected primary-expression before [ token
zc.cpp:9:21: error: expected primary-expression before ] token
zc.cpp:9:23: error: expected primary-expression before void
zc.cpp:9:29: error: expected ) before { token
zc.cpp:24:1: error: expected , or ; at end of input
zc.cpp:24:1: error: expected } at end of input

icpc zc.cpp
zc.cpp(23): error: expected an expression
lambdaTest([](void)->void{});
^

zc.cpp(9): error #303: explicit type is missing ("int" assumed)
auto result = ([](void) { return [](LAMBDA l) -> void { }; })(); // OK
^
....

I can provoke an internal error by setting icpc -std=c++0x which I suppose would justify a bug report, but this doesn't appear to reproduce your finding. Short of that, g++ and icpc appear in basic agreement about the demerits of my copy of your case.

Hi tim18.
Thank you for reply.

I suppose the GCC version you used does not support lambda expression syntax although you have turn on c++0x option. I may have described the situation more detailedly as following:

void Dummy(void)   
{   
       
}   
  
template    
void lambdaTest(LAMBDA lam)   
{   
    auto result = ([](void) { return [](LAMBDA l) -> void { }; })();    //OK for in both versions
    ([](LAMBDA l) -> void { l(); })(lam);  //OK in both versions
    ([&lam](void) -> void { lam(); })();   //OK in both versions
       
    void (*p)(void) = Dummy;   
    ([p](void) { return [p](void) -> void { (*p)(); }; })()();  //OK in both version  
       
    //ERROR in ver 11.1 for Mac but OK in ver 11.0 for Win
    ([&lam](void) { return [&lam](void) -> void { lam(); }; })();

    //ERROR in ver 11.1 for Mac but OK in ver 11.0 for Win
    ([](LAMBDA l) { return [&l](void) -> void { l(); }; })(lam); 
}   


int main(void)    
{   
    lambdaTest([](void)->void{});   
}  


Аватар пользователя om-sachan (Intel)

The lamda function are replacement for function objects. Could you please provide equivalent code using function objects?

Аватар пользователя Zenny Chen
Hi, Om. I'm glad you could reply to this.

I will provide the equivalent code with pleasure.

#define COMMENT(type_expr)

static void Dummy(void)      
{

}

//Original Code
template   COMMENT(support( void(void) ))
static void lambdaTest(LAMBDA lam)      
{
    //OK in both versions
    auto result = ([](void) { return [](LAMBDA l) -> void { }; })();  //Test1

    //OK in both versions
    ([](LAMBDA l) -> void { l(); })(lam);   //Test2

    //OK in both versions
    ([&lam](void) -> void { lam(); })();    //Test3
          
    void (*p)(void) = &Dummy;
    //OK in both versions
    ([p](void) { return [p](void) -> void { (*p)(); }; })()();  //Test4

    //ERROR in ver 11.1 for Mac but OK in ver 11.0 for Win   
    ([&lam](void) { return [&lam](void) -> void { lam(); }; })();   //Test5  
  
    //ERROR in ver 11.1 for Mac but OK in ver 11.0 for Win
    ([](LAMBDA l) { return [&l](void) -> void { l(); }; })(lam);    //Test6

    result(lam);
}


//< equivalent code
template   COMMENT(support( void(void) ))
static void LambdaTest(LAMBDA lam)
{
    //< Test1 equivalent
    struct
    {
        struct InnerLambda
        {
            void operator () (LAMBDA l)
            {

            }
        }innerLambda;

        InnerLambda operator () (void)
        {
            return innerLambda;
        }
    }lambda2;

    auto result = lambda2();
    // Test1 equivalent >

    //< Test2 equivalent
    struct
    {
        void operator () (LAMBDA l)
        {
            l();
        }
    }lambda3;

    lambda3(lam);
    // Test2 equivalent >

    //< Test3 equivalent
    class Lambda1
    {
    private:
        LAMBDA  val;
    public:
        Lambda1(LAMBDA l) : val(l)
        {

        }

        void operator () (void)
        {
            val();
        }
    }lambda4(lam);

    lambda4();
    // Test3 equivalent >

    void (*p)(void) = &Dummy;
    //< Test4 equivalent
    class Lambda2
    {
    private:

        void (*pFunc)(void);

        class InnerLambda
        {
        private:

            void (*pFunc)(void);

        public:

            InnerLambda(void (*p)(void)) : pFunc(p)
            {

            }

            void operator () (void)
            {
                (*pFunc)();
            }
        }innerLambda;

    public:
        Lambda2(void (*p)(void)) : pFunc(p), innerLambda(pFunc)
        {

        }

        InnerLambda operator () (void)
        {
            return innerLambda;
        }
    }lambda5(p);

    lambda5()();
    // Test4 equivalent >

    //< Test5 equivalent
    class Lambda3
    {
    private:

        LAMBDA lambda;

        class InnerLambda
        {
        private:

            LAMBDA lambda;

        public:

            InnerLambda(LAMBDA l) : lambda(l)
            {

            }

            void operator () (void)
            {
                lambda();
            }
        }innerLambda;

    public:

        Lambda3(LAMBDA l) : lambda(l), innerLambda(lambda)
        {

        }

        InnerLambda operator () (void)
        {
            return innerLambda;
        }
    }lambda6(lam);
    // Test5 equivalent >

    //< Test6 equivalent
    class Lambda4
    {
    private:

        class InnerLambda
        {
        private:

            LAMBDA lambda;

        public:

            InnerLambda(LAMBDA l) : lambda(l)
            {

            }

            void operator () (void)
            {
                lambda();
            }
        };

    public:

        InnerLambda operator () (LAMBDA l)
        {
            return InnerLambda(l);
        }
    }lambda7;

    lambda7(lam);
    // Test7 equivalent >

    result(lam);
}
// equivalent code > 


int main(void)
{
    lambdaTest([](void)->void{});

    //< equivalent code
    struct
    {
        void operator () (void)
        {

        }

    }lambda1;

    LambdaTest(lambda1);
    // equivalent code >
}

Wish that'll be helpful.

Аватар пользователя om-sachan (Intel)

I copied the function objects version of code in zc_functionobjects.cpp. I got many errors when tried to compile the code on Windows with Intel C++ compiler.

C:>icl -c /Qstd=c++0x zc_functionobjects.cpp

Intel C++ Compiler Professional for applications running on IA-32, Version 11.1 Build 20090624 Package ID: w_cproc_p_11.1.038
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.

zc_functionobjects.cpp
zc_functionobjects.cpp(2): error #77: this declaration has no storage class or type specifier
template COMMENT(support( void(void) ))
^

zc_functionobjects.cpp(2): error: "COMMENT" is not a function or static data member
template COMMENT(support( void(void) ))
^

zc_functionobjects.cpp(2): error: expected a ";"
template COMMENT(support( void(void) ))
^

zc_functionobjects.cpp(32): warning #12: parsing restarts here after previous syntax error
}lambda3;
^

zc_functionobjects.cpp(34): error #77: this declaration has no storage class ortype specifier
lambda3(lam);
^

zc_functionobjects.cpp(34): error: identifier "lam" is undefined
lambda3(lam);
^

zc_functionobjects.cpp(41): error: identifier "LAMBDA" is undefined
LAMBDA val;
^

zc_functionobjects.cpp(43): error: identifier "LAMBDA" is undefined
Lambda1(LAMBDA l) : val(l)
^

zc_functionobjects.cpp(54): error #303: explicit type is missing ("int" assumed)

lambda4();
^

zc_functionobjects.cpp(54): error: declaration is incompatible with "Lambda1 lambda4" (declared at line 52)
lambda4();
^

zc_functionobjects.cpp(57): error: identifier "Dummy" is undefined
void (*p)(void) = &Dummy;
^

zc_functionobjects.cpp(96): error: function returning function is not allowed
lambda5()();
^

zc_functionobjects.cpp(96): error: declaration is incompatible with "Lambda2 lambda5" (declared at line 94)
lambda5()();
^

zc_functionobjects.cpp(104): error: identifier "LAMBDA" is undefined
LAMBDA lambda;
^

zc_functionobjects.cpp(110): error: identifier "LAMBDA" is undefined
LAMBDA lambda;
^

zc_functionobjects.cpp(114): error: identifier "LAMBDA" is undefined
InnerLambda(LAMBDA l) : lambda(l)
^

zc_functionobjects.cpp(127): error: identifier "LAMBDA" is undefined
Lambda3(LAMBDA l) : lambda(l), innerLambda(lambda)
^

zc_functionobjects.cpp(148): error: identifier "LAMBDA" is undefined
LAMBDA lambda;
^

zc_functionobjects.cpp(152): error: identifier "LAMBDA" is undefined
InnerLambda(LAMBDA l) : lambda(l)
^

zc_functionobjects.cpp(165): error: identifier "LAMBDA" is undefined
InnerLambda operator () (LAMBDA l)
^

zc_functionobjects.cpp(171): error #77: this declaration has no storage class or type specifier
lambda7(lam);
^

zc_functionobjects.cpp(171): error: variable "lambda7" has already been defined
lambda7(lam);
^

zc_functionobjects.cpp(174): error #77: this declaration has no storage class or type specifier
result(lam);
^

zc_functionobjects.cpp(175): error: expected a declaration
}
^

zc_functionobjects.cpp(195): warning #12: parsing restarts here after previous syntax error

compilation aborted for zc_functionobjects.cpp (code 2)

Аватар пользователя Zenny Chen
Thank you Om.

But have you copied the macro definition of #define COMMENT(type_expr)

?

Аватар пользователя Zenny Chen
Quoting - Zenny Chen Thank you Om.

But have you copied the macro definition of #define COMMENT(type_expr)

?

Without the definition, there will be 24 error messages during compiling.

I don't know how you have copied the source code. Because it is not available to use "copy to clipboard" for mac OS X Leopard, I have to use "view plain" and then select all to copy. But this will be safer. And the color of macro definition highlight is not so attractive.

Anyway, thank you for your try, Om and tim.

Аватар пользователя om-sachan (Intel)

Thanks for clarification. I missed that.

Now I am able to compiler on Windows with icl. I am going to try now it on Linux and MAC OS.

Аватар пользователя Zenny Chen
What's strange is that I've just downloaded a version 11.1.038on Windows for evaluation. It is no problem.

I don't know whether the compiling error is relevant to the environment of Mac OS X Leopard.

However,only a few situations will generate an error for lambda expression.

Аватар пользователя Zenny Chen

The error message is:


Compilation aborted for /User/xxx/xxx.cpp (code 4) Location: Line Location Tool: 0
Аватар пользователя Zenny Chen
Well, should I report it to Intel Compiler Development Team?
Аватар пользователя om-sachan (Intel)
It seems there is an issue with Intel compiler for Linux.

The issue has been fixed in latest Intel C++ compiler for Linux version 11.1.046.

Could you please download and try the latest Intel C++ compiler 11.1?

Аватар пользователя Zenny Chen
Quoting - Om Sachan (Intel) It seems there is an issue with Intel compiler for Linux.

The issue has been fixed in latest Intel C++ compiler for Linux version 11.1.046.

Could you please download and try the latest Intel C++ compiler 11.1?

OK, I will try it. Thank you, Om.
Аватар пользователя Zenny Chen
Thanks, Om and Tim. I'll close this question. After all, expression is working well on Windows. I'm going to have a overall test on ICC for Mac OS X about C++0x features after C++0x has been issued.
Аватар пользователя quocanle (Intel)
Quoting - Zenny Chen Thanks, Om and Tim. I'll close this question. After all, expression is working well on Windows. I'm going to have a overall test on ICC for Mac OS X about C++0x features after C++0x has been issued.

Regarding the test case above that works with Intel compiler on Windows, but fail with Intel compiler on Mac OS X using version 11.1.058. That is a bug.You can reference it as Premier support issue #562598.

I'll update this thread when the issue is resolved.

Аватар пользователя Zenny Chen
Quoting - Qale (Intel)
Regarding the test case above that works with Intel compiler on Windows, but fail with Intel compiler on Mac OS X using version 11.1.058. That is a bug.You can reference it as Premier support issue #562598.

I'll update this thread when the issue is resolved.

Thanks, Qale.

Зарегистрируйтесь, чтобы оставить комментарий.