Compiler support of GNU Statement Expression

六眼飞鱼酱① 提交于 2019-11-27 15:27:06

The Intel C++ Compiler does not support statement expressions, even the last version that I know, version 13.0.

lrineau

As said in the comment of my previous answer, the Intel Compiler does support the statement expressions. But the emulation by Intel of that GNU extension is not complete, in C++. The following code is taken from CGAL-4.0 (http://www.cgal.org/):

#include <cassert>

struct A {
  int* p;

  A(int i) : p(new int(i)) {}
  ~A() { delete p; }
  int value() const { return *p;}
};

int main()
{
  int i = __extension__ ({ int j = 2; j+j; });
  assert(i == 4);

  // The Intel Compiler complains with the following error:
  // "error: destructible entities are not allowed inside of a statement
  // expression"
  // See http://software.intel.com/en-us/articles/cdiag1487/
  i = __extension__ ({ A a(2); A b(3); a.value() + b.value(); });

  assert(i == 5);
  return 0;
}

A comment in the code even give the error returned by the Intel Compiler, tested with version 11, 12, or 13.

http://software.intel.com/en-us/articles/cdiag1487/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!