Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does comma expression not work as expected when used as the placement argument?

#include <new>

using namespace std;

void f(void*)
{}

struct A
{};

int main()
{
    A a;

    f((a.~A(), &a)); // OK
    new (&a) A();    // OK

    new ((a.~A(), &a)) A(); // error C2059: syntax error : 'type'
}

I think (a.~A(), &a) is a valid expression which can be evaluated to a pointer value, so it should be accepted as the placement argument, why is the result not so?

My compiler is VC++ 2013 RC. Is this a compiler bug?

Update:

I have summitted a bug to connect.microsoft.com

like image 588
xmllmx Avatar asked Sep 27 '13 03:09

xmllmx


1 Answers

Yes, it is a compiler bug, the syntax is correct.

You can look at the grammar in the standard:

new-placement:
( expression-list )

And, a.~A(), &a is valid as an expression-list.

like image 90
Jesse Good Avatar answered Oct 03 '22 08:10

Jesse Good