Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error compiling on VS2022 #4593

Closed
1 of 2 tasks
chund opened this issue Jan 10, 2025 · 4 comments
Closed
1 of 2 tasks

error compiling on VS2022 #4593

chund opened this issue Jan 10, 2025 · 4 comments
Labels
kind: bug platform: visual studio related to MSVC state: needs more info the author of the issue needs to provide more details

Comments

@chund
Copy link

chund commented Jan 10, 2025

Description

this error:

json.hpp(19176,26): error C2760: syntax error: '&' was unexpected here; expected 'type specifier'

is given on line:

                    new (&*it) value_type{std::move(*next)};

Reproduction steps

compile json.hpp in Visual Studio 2022 latest version.
using C++17
having /sdl on or off does not make a difference.

Expected vs. actual results

compile without error ;)

Minimal code example

No response

Error messages

json.hpp(19176,26): error C2760: syntax error: '&' was unexpected here; expected 'type specifier'

Compiler and operating system

Windows Visual Studio 2022

Library version

3.11.3

Validation

@chund
Copy link
Author

chund commented Jan 10, 2025

related to #4386 ?

@nlohmann
Copy link
Owner

We use Visual Studio 2022 in our CI and can compile and test the library without issue, see https://github.com/nlohmann/json/blob/develop/.github/workflows/windows.yml#L92. Can you provide more information on what you compile exactly?

@nlohmann nlohmann added platform: visual studio related to MSVC state: needs more info the author of the issue needs to provide more details labels Jan 10, 2025
@gregmarr
Copy link
Contributor

I'm going to channel Raymond Chen and do some psychic debugging. Because this is on a placement new line, I think that you have something somewhere that redefines new for memory tracking purposes, like below.

#define new DEBUG_NEW
#define DEBUG_NEW new (__FILE__, __LINE__)

This breaks placement new calls because you end up with new (__FILE__, __LINE__) (&*it) value_type{std::move(*next)}; . Your options are to remove that, include the library header before that define, or add protection around the include so it doesn't apply.

#pragma push_macro("new")
#undef new
#include <nlohmann/json.hpp>
#pragma pop_macro("new")

@chund
Copy link
Author

chund commented Jan 11, 2025

This works
(&*it)->operator new(value_type{std::move(*next)});

And yes probably it is because of redefined new. Thanks for that 😀 should have considered that.

@chund chund closed this as completed Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug platform: visual studio related to MSVC state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

3 participants