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

Is this function designed intentionally? boost::date_time::c_time::gmtime doesn't touch the result pointer passed. #199

Open
fragrans opened this issue Nov 23, 2021 · 6 comments

Comments

@fragrans
Copy link

inline static std::tm* gmtime(const std::time_t* t, std::tm* result);

I assume this function will change the result pointer by filling the struct; but it doesn't;

Windows 10; MSVC 16.11.7

//! requires a pointer to a user created std::tm struct
inline
static std::tm* gmtime(const std::time_t* t, std::tm* result)
{
result = std::gmtime(t);
if (!result)
boost::throw_exception(std::runtime_error("could not convert calendar time to UTC time"));
return result;
}
#if defined(__clang__) // Clang has to be checked before MSVC
#pragma clang diagnostic pop
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400))

@fragrans
Copy link
Author

fragrans commented Dec 6, 2021

Any one?

@JeffGarland
Copy link
Collaborator

I'm not sure what the confusion is. The function calls gmtime to assign the result pointer and then returns it? Also this is really an implementation detail of the library, so not really part of the documented api.

@fragrans
Copy link
Author

fragrans commented Dec 7, 2021

the content of the 2nd argument (pointer result) passed to the function will not change;
didn't you see that?

@JeffGarland
Copy link
Collaborator

JeffGarland commented Dec 7, 2021

result = std::gmtime(t);

That changes it.

@fragrans
Copy link
Author

fragrans commented Dec 7, 2021

I am sorry, and confused. if you want to change this pointer, you need to

auto temp = std::gmtime(t); 
*result = *temp;

@jeking3
Copy link
Contributor

jeking3 commented Feb 20, 2022

@fragrans This is a C++03-compatible library so auto would not be appropriate, but I agree with you otherwise.

@JeffGarland if you look in date_clock_device.hpp, the implementation is passed a std::tm& but that is never filled in, and the returned std::tm* is going to be different than what was passed in for result. It does seem a bit confusing and likely a bug as there could be other bad assumptions made by consumers about get_local_time and get_universal_time based on the inputs.

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

3 participants