[Bug c++/67631] brace initialization bug
howard.hinnant at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Nov 14 17:55:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67631
--- Comment #4 from Howard Hinnant <howard.hinnant at gmail dot com> ---
This bug needs some attention because Howard Hinnant's date library is making
it common for people to hit this bug.
The date library:
https://github.com/HowardHinnant/date
This library is sufficiently popular and successful that it has been proposed
to the C++ committee for C++20.
Here is a short HelloWorld demonstrating the problem:
#include "date.h"
#include <iostream>
int
main()
{
using namespace date;
using namespace std::chrono;
year_month_day ymd = floor<days>(system_clock::now());
auto y = int{ymd.year()};
std::cout << y << '\n';
}
You can try this out without installing the library at:
http://melpon.org/wandbox/permlink/PodYB3AwdYNFKbMv
Tip of trunk gcc gives:
prog.cc: In function 'int main()':
prog.cc:10:28: error: cannot convert 'date::year' to 'int' in initialization
auto y = int{ymd.year()};
^
clang prints out the current year (UTC).
Changing the offending line to:
auto y = int(ymd.year());
is a workaround. But people really like the Uniform Initialization Syntax
(using braces).
More information about the Gcc-bugs
mailing list