Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange code breaks build in MSVC. What does it mean?

I am trying to include rapidxml into my current project. However, it would not build.

Visual Studio would complain about this piece of code (rapidxml.hpp:419+451):

419: void *memory = allocate_aligned(sizeof(xml_attribute<Ch>));
420: xml_attribute<Ch> *attribute = new(memory) xml_attribute<Ch>;

The compiler would say

rapidxml.hpp(420): error C2061: syntax error : identifier 'memory'

And I kind of see how this would confuse the compiler. It actually confuses me quite a bit, too. What is the (memory) part of new(memory) xml_attribute<Ch> doing there?

If I delete that (memory) part, it compiles just fine.
Also, gcc compiles it just fine with (memory) included.

Edit:
Oh, and I overloaded new with DEBUG_NEW to do some memory debugging. DEBUG_NEW does not support placement new.

like image 846
bastibe Avatar asked Jan 21 '11 08:01

bastibe


2 Answers

This is my suggestion. The "memory" itself is defined somewhere also as a macro, and is getting expanded which causes the problem. So search for #define.memory (using regular expressions) to see if memory is defined as a macro.

As for the next statement, this form:

new(allocator) ObjectType(...)

is used when you want to use your own memory allocator to allocate memory for you.

Hope this helps.

like image 68
Rafid Avatar answered Sep 22 '22 13:09

Rafid


Have you got #include <new> in that file?

like image 32
Tomek Avatar answered Sep 20 '22 13:09

Tomek