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

in-class initialization for type 'const T' is not yet implemented #591

Closed
chainke opened this issue May 22, 2017 · 10 comments
Closed

in-class initialization for type 'const T' is not yet implemented #591

chainke opened this issue May 22, 2017 · 10 comments
Labels
platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation state: please discuss please discuss the issue or vote for your favorite option

Comments

@chainke
Copy link

chainke commented May 22, 2017

Hey there,
I have a problem when compiling a project using json.hpp.
When I use Microsoft Visual Studio 2015 Update 3 on Windows7 everything worsk fine, but when I use Mircosoft Visual Studio 2017 on Windows 10, I get the following error:

\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C4579: 'nlohmann::detail::static_constnlohmann::detail::to_json_fn::value': in-class initialization for type 'const T' is not yet implemented; static member will remain uninitialized at runtime but use in constant-expressions is supported
2> with
2> [
2> T=nlohmann::detail::to_json_fn
2> ]
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(898): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "nlohmann::detail::static_constnlohmann::detail::to_json_fn".
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C2131: Ausdruck wurde nicht zu einer Konstanten ausgewertet.
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): note: Fehler wurde durch Rückgabe der Adresse eines temporären Elements oder eines Verweises zu einem temporären Element verursacht
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C2059: Syntaxfehler: "="
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C4579: 'nlohmann::detail::static_constnlohmann::detail::from_json_fn::value': in-class initialization for type 'const T' is not yet implemented; static member will remain uninitialized at runtime but use in constant-expressions is supported
2> with
2> [
2> T=nlohmann::detail::from_json_fn
2> ]
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(899): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "nlohmann::detail::static_constnlohmann::detail::from_json_fn".
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2784: "_Ty *std::begin(_Ty (&)[_Size]) noexcept": template-Argument für "_Ty (&)[_Size]" konnte nicht von "add_rvalue_reference::type" hergeleitet werden.
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xutility(1250): note: Siehe Deklaration von "std::begin"
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits(761): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer".
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits(790): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::is_nothrow_constructible<_Ty,nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &&>".
2> with
2> [
2> _Ty=nlohmann::json
2> ]
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(12931): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::is_nothrow_move_constructiblenlohmann::json".
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2893: Funktionsvorlage "unknown-type std::begin(const _Container &)" konnte nicht spezialisiert werden
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: Mit den folgenden Vorlagenargumenten:
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: "_Container=add_rvalue_reference::type"
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2893: Funktionsvorlage "unknown-type std::begin(_Container &)" konnte nicht spezialisiert werden
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: Mit den folgenden Vorlagenargumenten:
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: "_Container=add_rvalue_reference::type"
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2784: "const _Elem *std::begin(std::initializer_list<_Elem>) noexcept": template-Argument für "std::initializer_list<_Elem>" konnte nicht von "add_rvalue_reference::type" hergeleitet werden.
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\initializer_list(60): note: Siehe Deklaration von "std::begin"
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\Source\EyeTrackingPlugin\Private\MultipartMessage.cpp(46): warning C4456: Deklaration von "msg" blendet vorherige lokale Deklaration aus
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\Source\EyeTrackingPlugin\Private\MultipartMessage.cpp(23): note: Siehe Deklaration von "msg"
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C4579: 'nlohmann::detail::static_constnlohmann::detail::to_json_fn::value': in-class initialization for type 'const T' is not yet implemented; static member will remain uninitialized at runtime but use in constant-expressions is supported
2> with
2> [
2> T=nlohmann::detail::to_json_fn
2> ]
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(898): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "nlohmann::detail::static_constnlohmann::detail::to_json_fn".
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C2131: Ausdruck wurde nicht zu einer Konstanten ausgewertet.
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): note: Fehler wurde durch Rückgabe der Adresse eines temporären Elements oder eines Verweises zu einem temporären Element verursacht
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C2059: Syntaxfehler: "="
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(887): error C4579: 'nlohmann::detail::static_constnlohmann::detail::from_json_fn::value': in-class initialization for type 'const T' is not yet implemented; static member will remain uninitialized at runtime but use in constant-expressions is supported
2> with
2> [
2> T=nlohmann::detail::from_json_fn
2> ]
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(899): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "nlohmann::detail::static_constnlohmann::detail::from_json_fn".
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2784: "_Ty *std::begin(_Ty (&)[_Size]) noexcept": template-Argument für "_Ty (&)[_Size]" konnte nicht von "add_rvalue_reference::type" hergeleitet werden.
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xutility(1250): note: Siehe Deklaration von "std::begin"
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits(761): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer".
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits(790): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::is_nothrow_constructible<_Ty,nlohmann::basic_jsonstd::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer &&>".
2> with
2> [
2> _Ty=nlohmann::json
2> ]
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(12931): note: Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::is_nothrow_move_constructiblenlohmann::json".
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2893: Funktionsvorlage "unknown-type std::begin(const _Container &)" konnte nicht spezialisiert werden
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: Mit den folgenden Vorlagenargumenten:
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: "_Container=add_rvalue_reference::type"
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2893: Funktionsvorlage "unknown-type std::begin(_Container &)" konnte nicht spezialisiert werden
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: Mit den folgenden Vorlagenargumenten:
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): note: "_Container=add_rvalue_reference::type"
2>D:\Uni\Bachelorarbeit\EyeTracking4_15\Plugins\EyeTrackingPlugin\ThirdParty\PupilLabs\include\json.hpp(6482): error C2784: "const _Elem *std::begin(std::initializer_list<_Elem>) noexcept": template-Argument für "std::initializer_list<_Elem>" konnte nicht von "add_rvalue_reference::type" hergeleitet werden.
2>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\initializer_list(60): note: Siehe Deklaration von "std::begin"

Is either Visual Studio 2017 or Windows 10 not supported yet?

@nlohmann nlohmann added the platform: visual studio related to MSVC label May 22, 2017
@nlohmann
Copy link
Owner

Visual Studio 2017 is supported. We run Microsoft (R) Build Engine version 15.1.548.43366 with AppVeyor, see https://ci.appveyor.com/project/nlohmann/json.

@nlohmann
Copy link
Owner

nlohmann commented Jun 2, 2017

Could you please provide an example that triggers this error?

@nlohmann
Copy link
Owner

nlohmann commented Jun 7, 2017

Any news on this?

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Jun 7, 2017
@chainke
Copy link
Author

chainke commented Jun 7, 2017

Sorry for the late reply and thank you!

I'm using json.hpp within a plugin for Unreal Engine 4 and included it in the header file:
#include "json.hpp"
In the cpp file I made a namespace:
using json = nlohmann::json;
Then I recieve a string looking similar to this:

string jsonString = {"timestamp":62572.2, 
"norm_pos":[0.524542, 0.49178], 
"base_data":[{
	"id":0, 
	"method":"2d c++", 
	"norm_pos":[0.524542, 0.49178], 
	"confidence":0.745419, 
	"timestamp":62572.2, 
	"diameter":64.9183, 
	"ellipse":{
		"axes":[19.7713, 64.9183], 
		"center":[335.707, 243.946], 
		"angle":156.647}
	}], 
"confidence":0.745419}

I'm trying to access the data with json by parsing it like this:
auto jsonMap = json::parse(jsonString.c_str());

But then I get the error listet above. I tried it on two other computers (Win7 and Win10, VisualStudio 2015 and 2017) where it works fine. I also reinstalled VisualStudio on the computer where it isn't working but the same error occures.

@nlohmann
Copy link
Owner

So this program does not compile with MSVC2017?

#include "json.hpp"

using json = nlohmann::json;

int main()
{
    std::string jsonString = R"({
        "timestamp":62572.2,
        "norm_pos":[0.524542, 0.49178],
        "base_data":[{
                     "id":0,
                     "method":"2d c++",
                     "norm_pos":[0.524542, 0.49178],
                     "confidence":0.745419,
                     "timestamp":62572.2,
                     "diameter":64.9183,
                     "ellipse":{
                     "axes":[19.7713, 64.9183],
                     "center":[335.707, 243.946],
                     "angle":156.647}
                     }],
    "confidence":0.745419})";

    auto jsonMap = json::parse(jsonString.c_str());
    std::cout << jsonMap << std::endl;
}

@chainke
Copy link
Author

chainke commented Jun 14, 2017

Hmm this code works for me. I'm going to figure out how the code I used differs from this one.
Thank you!

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jul 8, 2017
@nlohmann
Copy link
Owner

nlohmann commented Jul 8, 2017

Any news on this?

@gutwinski
Copy link

I have come across the same problem with Visual Studio Professional 2015. My code is rather simple:

#include "stdafx.h"
#include "nlohmann\json.hpp"

int main()
{
    return 0;
}

Yet, it return these faults:

1>  ConsoleApplication1.cpp
1>[...]\projects\consoleapplication1\consoleapplication1\nlohmann\detail\meta\cpp_future.hpp(57): error C4579: 'nlohmann::detail::static_const<nlohmann::detail::from_json_fn>::value': in-class initialization for type 'const T' is not yet implemented; static member will remain uninitialized at runtime but use in constant-expressions is supported
1>          with
1>          [
1>              T=nlohmann::detail::from_json_fn
1>          ]
1>[...]\projects\consoleapplication1\consoleapplication1\nlohmann\detail\conversions\from_json.hpp(387): note: see reference to class template instantiation 'nlohmann::detail::static_const<nlohmann::detail::from_json_fn>' being compiled
1>[...]\projects\consoleapplication1\consoleapplication1\nlohmann\detail\meta\cpp_future.hpp(57): error C2131: expression did not evaluate to a constant
1>[...]\projects\consoleapplication1\consoleapplication1\nlohmann\detail\meta\cpp_future.hpp(57): note: failure was caused by returning the address of or a reference to a temporary
1>[...]\projects\consoleapplication1\consoleapplication1\nlohmann\detail\meta\cpp_future.hpp(57): error C4579: 'nlohmann::detail::static_const<nlohmann::detail::to_json_fn>::value': in-class initialization for type 'const T' is not yet implemented; static member will remain uninitialized at runtime but use in constant-expressions is supported
1>          with
1>          [
1>              T=nlohmann::detail::to_json_fn
1>          ]
1>[...]\projects\consoleapplication1\consoleapplication1\nlohmann\detail\conversions\to_json.hpp(345): note: see reference to class template instantiation 'nlohmann::detail::static_const<nlohmann::detail::to_json_fn>' being compiled
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Since the topic was closed for @chainke , I'd like to know how. Thanks in advance!

@yyt6801
Copy link

yyt6801 commented Jun 28, 2022

I also encountered the same problem when developing with vs2015. After reading the comments above, it did not help substantially.
It can be used normally in vs2017 and above, but there will be problems with vs2015...
Because the version above vs2015 is extremely troublesome to install in an offline environment, and I have to use vs for development...

After reading the source code, it contains a lot of features above cpp11. In vs2015 and below, it can't even compile normally.

@mohit-mittal-cosm
Copy link

Sorry for the late reply and thank you!

I'm using json.hpp within a plugin for Unreal Engine 4 and included it in the header file: #include "json.hpp" In the cpp file I made a namespace: using json = nlohmann::json; Then I recieve a string looking similar to this:

string jsonString = {"timestamp":62572.2, 
"norm_pos":[0.524542, 0.49178], 
"base_data":[{
	"id":0, 
	"method":"2d c++", 
	"norm_pos":[0.524542, 0.49178], 
	"confidence":0.745419, 
	"timestamp":62572.2, 
	"diameter":64.9183, 
	"ellipse":{
		"axes":[19.7713, 64.9183], 
		"center":[335.707, 243.946], 
		"angle":156.647}
	}], 
"confidence":0.745419}

I'm trying to access the data with json by parsing it like this: auto jsonMap = json::parse(jsonString.c_str());

But then I get the error listet above. I tried it on two other computers (Win7 and Win10, VisualStudio 2015 and 2017) where it works fine. I also reinstalled VisualStudio on the computer where it isn't working but the same error occures.

@chainke i m also trying to use this library inside my plugin in unreal engine. can you help with the steps on how to include it in my unreal engine plugin. I am quite new to unreal, and links would also be helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: visual studio related to MSVC solution: proposed fix a fix for the issue has been proposed and waits for confirmation state: please discuss please discuss the issue or vote for your favorite option
Projects
None yet
Development

No branches or pull requests

5 participants