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

Checked iterator warnings when building with MSVC 2015 #1947

Closed
deleoDev91 opened this issue Oct 21, 2020 · 8 comments
Closed

Checked iterator warnings when building with MSVC 2015 #1947

deleoDev91 opened this issue Oct 21, 2020 · 8 comments

Comments

@deleoDev91
Copy link

Hi, I'm using spdlog which uses your library. I tried to update the spdlog version but my project failed to build because fmt dont use stdext checked iterartor utilities at std copy calls in include\fmt\format.h(3016). Compiler says that it can be avoided if I desable certain warnings, but I dont want to do this unless its strictly neccessary. For now I solved it downloading and older version of fmt but It would be nice to dont have to depend from an older version to avoid compatibility problems. Thanks for the help.

@vitaut
Copy link
Contributor

vitaut commented Oct 21, 2020

Are you referring to MSVC 2015 by msvc14? What errors do you get?

The current master compiles fine on 2015: https://ci.appveyor.com/project/vitaut/fmt/builds/35876519.

@deleoDev91
Copy link
Author

By MSVC 14 I refer myself to VS2015, if its that what are you asking(v140). It gives me problem at std:copy_n. It says that its copying a memory using unchecked limits in iterators. Actually, this isnt a bug but msvc doesnt like using std copy without using aditional stuff from stdext. I had this problem in a case when i was trying copy data from a buffer to a different destination using only pointers. Once I used stdext::checked_array_iterator the error disappear.

By the way, I checked the build you posted and it gives the same messages (and the same problem with std copy), the only difference is that mine fails at the end. Maybe the problem is some configuration values in my project

@vitaut vitaut changed the title Fail to build wit msvc14 Checked iterator warnings when building with MSVC 2015 Oct 21, 2020
@vitaut
Copy link
Contributor

vitaut commented Jan 18, 2021

One repro from #2092:

#include <fmt/core.h>

int main() {
  fmt::format(L"{}_{:04d}-{:02d}-{:02d}{}", L"filename", 2020, 1, 12, L".txt"};
}

@Othereum
Copy link
Contributor

Othereum commented Mar 5, 2021

Still not fixed

c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
  fmt\include\fmt\chrono.h(449): note: '_OutIt std::copy<T*,fmt::v7::detail::buffer_appender<T>>(_InIt,_InIt,_OutIt)'
          with
          [
              _OutIt=fmt::v7::detail::buffer_appender<char>,
              T=char,
              _InIt=char *
          ]

return std::copy(buf.begin(), buf.end(), ctx.out());

Compiled with /W4 /sdl /WX- in debug configuration

@tsilia
Copy link

tsilia commented Apr 27, 2021

Hello.

I'm also using VS2015 update3 (toolset v140) and getting two compiler errors C4996:

c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): error C4996: 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate': Call to 'std::uninitialized_copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): note: see declaration of 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate'
  fmt\format.h(501): note: see reference to function template instantiation '_FwdIt std::uninitialized_copy<InputIt,OutChar*>(_InIt,_InIt,_FwdIt)' being compiled
          with
          [
              _FwdIt=char *,
              InputIt=const char *,
              OutChar=char,
              _InIt=const char *
          ]

and

c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): note: see declaration of 'std::copy::_Unchecked_iterators::_Deprecate'
  fmt\chrono.h(455): note: see reference to function template instantiation '_OutIt std::copy<T*,fmt::v7::detail::buffer_appender<T>>(_InIt,_InIt,_OutIt)' being compiled
          with
          [
              _OutIt=fmt::v7::detail::buffer_appender<char>,
              T=char,
              _InIt=char *
          ]

Here's the minimal example to reproduces the issue (taken from https://fmt.dev/latest/api.html#chrono-api):

#include <fmt/chrono.h>

const std::time_t t = std::time(nullptr);
fmt::print("{:%Y-%m-%d}", fmt::localtime(t));

@vitaut
Copy link
Contributor

vitaut commented Apr 27, 2021

Suppressed the warnings in ab7c33e.

@vitaut vitaut closed this as completed Apr 27, 2021
@tsilia
Copy link

tsilia commented Apr 27, 2021

Good job, it's now working with SDL checks on.
Thank you!

@deleoDev91
Copy link
Author

Downloaded, compiled, tested and everything works ok. Good job and thank you

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

No branches or pull requests

4 participants