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

Visual Studio 2015 C++ compiler cannot compile certain constexpr constructions #60

Closed
hmaarrfk opened this issue Jan 1, 2020 · 8 comments
Assignees
Milestone

Comments

@hmaarrfk
Copy link

hmaarrfk commented Jan 1, 2020

int32_t x = 0;

I'm getting an error on this line of code when trying to compile with VS 14.1

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=106870&view=logs&j=2cc45e14-23e3-52d7-b33a-8c2744410b97&t=21c44aa7-1ae3-5312-cacc-7f19fefc82f4&l=688

This build will likely get destroyed, so I'm copying the error message

[1/22] Building CXX object CMakeFiles\charls.dir\src\charls_jpegls_decoder.cpp.obj
FAILED: CMakeFiles/charls.dir/src/charls_jpegls_decoder.cpp.obj 
C:\PROGRA~2\MICROS~1.0\VC\bin\amd64\cl.exe  /nologo /TP -DCHARLS_LIBRARY_BUILD -Dcharls_EXPORTS -I..\include -MD -GL  /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /O2 /Ob2 /DNDEBUG   -std:c++14 /showIncludes /FoCMakeFiles\charls.dir\src\charls_jpegls_decoder.cpp.obj /FdCMakeFiles\charls.dir\ /FS -c ..\src\charls_jpegls_decoder.cpp
..\include\charls/charls.h(488): warning C4800: 'int32_t': forcing value to bool 'true' or 'false' (performance warning)
d:\bld\charls_1577727546940\work\src\util.h(121): error C3250: 'x': declaration is not allowed in 'constexpr' function body
d:\bld\charls_1577727546940\work\src\util.h(121): error C3249: illegal statement or sub-expression for 'constexpr' function
d:\bld\charls_1577727546940\work\src\util.h(122): error C3249: illegal statement or sub-expression for 'constexpr' function
d:\bld\charls_1577727546940\work\src\util.h(124): error C3249: illegal statement or sub-expression for 'constexpr' function
d:\bld\charls_1577727546940\work\src\util.h(124): note: see usage of '++'
d:\bld\charls_1577727546940\work\src\util.h(126): error C3256: 'x': variable use does not produce a constant expression
[2/22] Building CXX object CMakeFiles\charls.dir\src\charls_jpegls_encoder.cpp.obj
FAILED: CMakeFiles/charls.dir/src/charls_jpegls_encoder.cpp.obj 
C:\PROGRA~2\MICROS~1.0\VC\bin\amd64\cl.exe  /nologo /TP -DCHARLS_LIBRARY_BUILD -Dcharls_EXPORTS -I..\include -MD -GL  /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MD /O2 /Ob2 /DNDEBUG   -std:c++14 /showIncludes /FoCMakeFiles\charls.dir\src\charls_jpegls_encoder.cpp.obj /FdCMakeFiles\charls.dir\ /FS -c ..\src\charls_jpegls_encoder.cpp
..\include\charls/charls.h(488): warning C4800: 'int32_t': forcing value to bool 'true' or 'false' (performance warning)
d:\bld\charls_1577727546940\work\src\util.h(121): error C3250: 'x': declaration is not allowed in 'constexpr' function body
d:\bld\charls_1577727546940\work\src\util.h(121): error C3249: illegal statement or sub-expression for 'constexpr' function
d:\bld\charls_1577727546940\work\src\util.h(122): error C3249: illegal statement or sub-expression for 'constexpr' function
d:\bld\charls_1577727546940\work\src\util.h(124): error C3249: illegal statement or sub-expression for 'constexpr' function
d:\bld\charls_1577727546940\work\src\util.h(124): note: see usage of '++'
d:\bld\charls_1577727546940\work\src\util.h(126): error C3256: 'x': variable use does not produce a constant expression
[3/22] Building CXX object CMakeFiles\charls.dir\src\jpegls.cpp.obj
d:\bld\charls_1577727546940\work\src\scan.h(82): error C3249: illegal statement or sub-expression for 'constexpr' function
d:\bld\charls_1577727546940\work\src\scan.h(88): error C3250: 'mappedError': declaration is not allowed in 'constexpr' function body
d:\bld\charls_1577727546940\work\src\scan.h(88): error C3249: illegal statement or sub-expression for 'constexpr' function
ninja: build stopped: subcommand failed.

@hmaarrfk
Copy link
Author

hmaarrfk commented Jan 1, 2020

I think this might be because VS2015 might not implement all the features of constexpr

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3652.html

There are a few other declarations I had to make inline.

@vbaderks
Copy link
Contributor

vbaderks commented Jan 1, 2020

Yes, your right. VS2015 is not 100% C++14 compatible, but it still supported by Microsoft until October 2025. I will have a look.

@hmaarrfk
Copy link
Author

hmaarrfk commented Jan 1, 2020

@vbaderks vbaderks self-assigned this Jan 1, 2020
@vbaderks vbaderks added this to the 2.1.1 milestone Jan 1, 2020
@vbaderks vbaderks changed the title declaration is not allowed in 'constexpr' Visual Studio 2015 C++ compiler cannot compile certain constexpr constructions Jan 1, 2020
vbaderks added a commit that referenced this issue Jan 1, 2020
Visual Studio 2015 is mostly C++14 compatible, but some constexpr constructions are not supported.  Add a helper macro to make it possible to use VS2015  to compile CharLS 2.1.0. See also #60
@vbaderks
Copy link
Contributor

vbaderks commented Jan 2, 2020

Hi Mark,
Thanks for the patch. The version on the master branch now compiles with Visual Studio 2015.
This improvement will be included in v2.1.1. Is having this fix for you on the master branch enough?

@hmaarrfk
Copy link
Author

hmaarrfk commented Jan 2, 2020

Are you 100% sure that compiles? Without the inline word, I think I was having failures due to multiple definitions of the same function.

We can patch things up with conda-forge, and I can try out your patchc in a bit.

@vbaderks
Copy link
Contributor

vbaderks commented Jan 2, 2020

inline is used and needed for the free functions. In portable_anymap_file.h it is not needed as class member functions declared inside a class are auto inline. It compiles on my local VS 2015 setup.

I was already thinking of adding an Azure CI pipeline to ensure older versions of VS are auto tested, will give that task some more prio.

@hmaarrfk
Copy link
Author

hmaarrfk commented Jan 2, 2020

Hmm ok. Thanks for the detailed explanation. I didn't know about autoinline

Yeah moving to Azure is OK, you just have to want to buy into yet an other platform.

I'm trying to build with your patch now

conda-forge/charls-feedstock#3 (comment)

It seems to have worked.

@hmaarrfk
Copy link
Author

hmaarrfk commented Jan 2, 2020

You can close if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants