Opened 11 years ago

Closed 9 years ago

#5550 closed Bugs (fixed)

Missing initializer warning in date_time/date_facet.hpp

Reported by: Derek McGowan <derek@…> Owned by: az_sw_dude
Milestone: To Be Determined Component: date_time
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc: manish.mulimani@…, derek@…

Description

include/boost/date_time/date_facet.hpp is causing a compiler warning

Compiler: gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)

Compiler Options: g++4 -shared -fpic -g -Wall -Woverloaded-virtual -Werror -Wl,--warn-shared-textrel -Wl,--fatal-warnings

cc1plus: warnings being treated as errors
boost_1_46_1/include/boost/date_time/date_facet.hpp: In member function ‘OutItrT boost::date_time::date_facet<date_type, CharT, OutItrT>::put(OutItrT, std::ios_base&, CharT, const typename date_type::month_type&) const [with date_type = boost::gregorian::date, CharT = char, OutItrT = std::ostreambuf_iterator<char, std::char_traits<char> >]’:
boost_1_46_1/include/boost/date_time/gregorian/gregorian_io.hpp:243:   instantiated from ‘std::basic_ostream<_CharT, _Traits>& boost::gregorian::operator<<(std::basic_ostream<_CharT, _Traits>&, const boost::gregorian::greg_month&) [with CharT = char, TraitsT = std::char_traits<char>]’
<source>.cpp:##:   instantiated from here
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_sec’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_min’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_hour’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_mday’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_mon’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_year’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_wday’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_yday’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_isdst’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_gmtoff’
boost_1_46_1/include/boost/date_time/date_facet.hpp:211: warning: missing initializer for member ‘tm::tm_zone’

std::tm dtm = {}; should be changed to something like std::tm dtm = std::tm();

This same issue was addressed and fixed in #3563

Attachments (1)

patch_for_ticket#5550.diff (1.2 KB ) - added by Manish Mulimani <manish.mulimani@…> 11 years ago.
Patch for the bug.

Download all attachments as: .zip

Change History (10)

comment:1 by Derek McGowan <derek@…>, 11 years ago

Component: Nonedate_time
Owner: set to az_sw_dude

Setting component to date_time

comment:2 by Manish Mulimani <manish.mulimani@…>, 11 years ago

Can I work on this bug?

by Manish Mulimani <manish.mulimani@…>, 11 years ago

Attachment: patch_for_ticket#5550.diff added

Patch for the bug.

comment:3 by Manish Mulimani <manish.mulimani@…>, 11 years ago

Cc: manish.mulimani@… added

comment:4 by Derek McGowan <derek@…>, 11 years ago

Cc: derek@… added
Severity: CosmeticProblem

This is breaking our compilation, so I am upgrading it from cosmetic to a problem. Please submit patch.

comment:5 by Marshall Clow, 10 years ago

(In [80710]) Use memset instead of default constructor (std::tm) for deficient compilers; Refs #5550

comment:6 by Marshall Clow, 10 years ago

Resolution: fixed
Status: newclosed

(In [80797]) Merge bug fixes to release; Fixes #5550 Fixes #6136 Fixes #6513 Fixes #7111 Fixes #7112 Fixes #7113 Fixes #7342 Fixes #7426

comment:7 by Johan Lundberg <lundberj@…>, 9 years ago

Resolution: fixed
Status: closedreopened
Version: Boost 1.46.1Boost 1.54.0

This problem is there at two more places in another file (boost 1.54 beta1), giving the same errors/warnings as above.

/date_time/strings_from_facet.hpp:53:20: warning: missing initializer for member ‘tm::tm_gmtoff’ [-Wmissing-field-initializers] (and ten more like it)

/date_time/strings_from_facet.hpp:106:20: warning: missing initializer for member ‘tm::tm_zone’ [-Wmissing-field-initializers] (and ten more like it)

Now, changeset https://svn.boost.org/trac/boost/changeset/80797 suggest the change from

tm tm_value = {};

to

std::tm dtm; std::memset(&dtm, 0, sizeof(dtm));

I've made this change (at two places) and that silences all related warnings. Using the more obvious tm_value = {0,0,0,0,0,0,0,0,0} is not a good idea since some implementations add their own values at the end of the struct.

How to reproduce:

#include "date_time/posix_time/posix_time.hpp" int main(){}

compile with gcc4.7.2, default options.

comment:8 by Marshall Clow, 9 years ago

(In [84835]) Fixed more compiler warnings; Refs #5550

comment:9 by Marshall Clow, 9 years ago

Resolution: fixed
Status: reopenedclosed

(In [84860]) Merge bug fixes to release. Fixes #6136. Fixes #5550

Note: See TracTickets for help on using tickets.