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

VS2017 compiler suggests using constexpr if #1204

Closed
DragonOsman opened this issue Aug 20, 2018 · 5 comments
Closed

VS2017 compiler suggests using constexpr if #1204

DragonOsman opened this issue Aug 20, 2018 · 5 comments
Assignees
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@DragonOsman
Copy link

I'm making a bug report, but it's not really a bug. It's something between a bug and a feature request. Basically, the MSVC compiler (latest version in VS2017) is suggesting to use constexpr if in the file single_include\nlohmann\json,hpp on line 1966. The warning is:

warning C4127: conditional expression is constant
note: consider using 'if constexpr' statement instead

Also, on single_include\nlohmann\json.hpp(1962) (`962 is the line number):

note: while compiling class template member function 'std::char_traits<char>::int_type nlohmann::detail::wide_string_input_adapter<std::u32string>::get_character(void) noexcept'
@nlohmann
Copy link
Owner

Thanks for the info! Unfortunately, I am not sure what to do with it, because we target C++11, and constexpr if are a C++17 extension IIRC. So the best I could do to silence this warning would be to decorate it with some macros. Not sure if this is worth it, though...

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Aug 23, 2018
@jk-jeon
Copy link

jk-jeon commented Aug 25, 2018

VS2017 now properly supports feature testing macros, which others already have supported.
How about this?

#ifdef __cpp_if_constexpr
  if constexpr( ... )
#else
  if( ... )
#endif

@theodelrieu
Copy link
Contributor

I would rather write a metafunction than introduce some ifdefs.

@stale
Copy link

stale bot commented Sep 24, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Sep 24, 2018
@stale stale bot closed this as completed Oct 1, 2018
@nlohmann nlohmann added this to the Release 3.3.0 milestone Oct 4, 2018
@nlohmann nlohmann self-assigned this Oct 4, 2018
@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed state: please discuss please discuss the issue or vote for your favorite option state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated labels Oct 4, 2018
@nlohmann
Copy link
Owner

nlohmann commented Oct 4, 2018

Fixed by merging #1272.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

4 participants