|
Boost : |
Subject: [boost] [optional] Warnings about uninitialized values
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-06-21 18:28:24
Hi,
When I use boost::optional I often see gcc warnings about using possibly
uninitialized values. I've seen such warnings in my projects outside Boost but
now I encountered them in Boost.Log. Building the current develop with gcc 4.8
I see this:
./boost/date_time/constrained_value.hpp: In member function
âboost::shared_ptr<boost::log::v2_mt_posix::sinks::sink>
boost::log::v2_mt_posix::
{anonymous}::default_text_file_sink_factory<CharT>::create_sink(const
settings_section&) [with CharT = wchar_t; boost::log::v2_mt_posix::
{anonymous}::default_text_file_sink_factory<CharT>::settings_section =
boost::log::v2_mt_posix::basic_settings_section<wchar_t>]â:
./boost/date_time/constrained_value.hpp:76:7: warning: â*((void*)& day +2)â
may be used uninitialized in this function [-Wmaybe-uninitialized]
value_ = value;
^
libs/log/src/init_from_settings.cpp:172:32: note: â*((void*)& day +2)â was
declared here
optional< unsigned short > day;
^
libs/log/src/init_from_settings.cpp:249:87: warning: â*((void*)& weekday +4)â
may be used uninitialized in this function [-Wmaybe-uninitialized]
return sinks::file::rotation_at_time_point(weekday.get(), hour,
minute, second);
^
libs/log/src/init_from_settings.cpp:171:37: note: â*((void*)& weekday +4)â was
declared here
optional< date_time::weekdays > weekday;
^
I attached the full log for convenience. The code in question is this
function:
https://github.com/boostorg/log/blob/develop/src/init_from_settings.cpp#L171
Note that at line 248 and below I check that the optional is filled before
using it, so there is no way I'll be accessing any uninitialized data (that
is, if boost::optional behaves correctly).
I suspect this may be a compiler bug. I tried to create a minimal example to
reproduce it but the warning doesn't show in a simple context. However, I'd
like it to be worked around somehow (unless it's an actual bug in
boost::optional).
Any suggestions? Am I missing a bug in my code?
Performing configuration checks
- symlinks supported : yes (cached)
- x86 : yes (cached)
- compiler-supports-ssse3 : yes (cached)
- has_icu builds : yes (cached)
- lockfree boost::atomic_flag : yes (cached)
- compiler-supports-avx2 : yes (cached)
Component configuration:
- atomic : not building
- chrono : not building
- container : not building
- context : not building
- coroutine : not building
- date_time : not building
- exception : not building
- filesystem : not building
- graph : not building
- graph_parallel : not building
- iostreams : not building
- locale : not building
- log : building
- math : not building
- mpi : not building
- program_options : not building
- python : not building
- random : not building
- regex : not building
- serialization : not building
- signals : not building
- sync : not building
- system : not building
- test : not building
- thread : not building
- timer : not building
- wave : not building
...patience...
...patience...
...patience...
...patience...
...found 7290 targets...
...updating 149 targets...
common.mkdir stage
common.mkdir bin.v2/libs
common.mkdir bin.v2/libs/filesystem
common.mkdir bin.v2/libs/regex
common.mkdir bin.v2/libs/thread
common.mkdir bin.v2/libs/date_time
common.mkdir bin.v2/libs/system
common.mkdir bin.v2/libs/chrono
common.mkdir bin.v2/libs/log
common.mkdir bin.v2/libs/chrono/build
common.mkdir bin.v2/libs/thread/build
common.mkdir bin.v2/libs/log/build
common.mkdir bin.v2/libs/system/build
common.mkdir bin.v2/libs/regex/build
common.mkdir bin.v2/libs/chrono/build/gcc-4.8
common.mkdir bin.v2/libs/thread/build/gcc-4.8
common.mkdir bin.v2/libs/filesystem/build
common.mkdir bin.v2/libs/date_time/build
common.mkdir stage/lib
common.mkdir bin.v2/libs/regex/build/gcc-4.8
common.mkdir bin.v2/libs/system/build/gcc-4.8
common.mkdir bin.v2/libs/log/build/gcc-4.8
common.mkdir bin.v2/libs/date_time/build/gcc-4.8
common.mkdir bin.v2/libs/filesystem/build/gcc-4.8
common.mkdir bin.v2/libs/thread/build/gcc-4.8/release
common.mkdir bin.v2/libs/log/build/gcc-4.8/release
common.mkdir bin.v2/libs/chrono/build/gcc-4.8/release
common.mkdir bin.v2/libs/regex/build/gcc-4.8/release
common.mkdir bin.v2/libs/thread/build/gcc-4.8/release/debug-symbols-on
common.mkdir bin.v2/libs/chrono/build/gcc-4.8/release/debug-symbols-on
common.mkdir bin.v2/libs/system/build/gcc-4.8/release
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release
common.mkdir bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release/debug-symbols-on
common.mkdir bin.v2/libs/filesystem/build/gcc-4.8/release
common.mkdir bin.v2/libs/system/build/gcc-4.8/release/debug-symbols-on
common.mkdir bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on
common.mkdir bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix
common.mkdir bin.v2/libs/thread/build/gcc-4.8/release/debug-symbols-on/threading-multi
common.mkdir bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi
common.mkdir bin.v2/libs/chrono/build/gcc-4.8/release/debug-symbols-on/threading-multi
common.mkdir bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on
common.mkdir bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi
common.mkdir bin.v2/libs/system/build/gcc-4.8/release/debug-symbols-on/threading-multi
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release/debug-symbols-on/threading-multi
common.mkdir bin.v2/libs/thread/build/gcc-4.8/release/debug-symbols-on/threading-multi/pthread
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release/debug-symbols-on/threading-multi/gregorian
common.mkdir bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi
gcc.compile.c++ bin.v2/libs/thread/build/gcc-4.8/release/debug-symbols-on/threading-multi/future.o
gcc.compile.c++ bin.v2/libs/system/build/gcc-4.8/release/debug-symbols-on/threading-multi/error_code.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/codecvt_error_category.o
gcc.link.dll bin.v2/libs/system/build/gcc-4.8/release/debug-symbols-on/threading-multi/libboost_system.so.1.56.0
common.copy stage/lib/libboost_system.so.1.56.0
ln-UNIX stage/lib/libboost_system.so
gcc.compile.c++ bin.v2/libs/chrono/build/gcc-4.8/release/debug-symbols-on/threading-multi/thread_clock.o
gcc.compile.c++ bin.v2/libs/chrono/build/gcc-4.8/release/debug-symbols-on/threading-multi/chrono.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/path_traits.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/utf8_codecvt_facet.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/portability.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/windows_file_codecvt.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/unique_path.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/path.o
gcc.compile.c++ bin.v2/libs/thread/build/gcc-4.8/release/debug-symbols-on/threading-multi/pthread/once.o
gcc.compile.c++ bin.v2/libs/date_time/build/gcc-4.8/release/debug-symbols-on/threading-multi/gregorian/date_generators.o
gcc.compile.c++ bin.v2/libs/date_time/build/gcc-4.8/release/debug-symbols-on/threading-multi/gregorian/greg_weekday.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/attribute_name.o
gcc.compile.c++ bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/operations.o
gcc.link.dll bin.v2/libs/filesystem/build/gcc-4.8/release/debug-symbols-on/threading-multi/libboost_filesystem.so.1.56.0
common.copy stage/lib/libboost_filesystem.so.1.56.0
ln-UNIX stage/lib/libboost_filesystem.so
gcc.compile.c++ bin.v2/libs/date_time/build/gcc-4.8/release/debug-symbols-on/threading-multi/gregorian/greg_month.o
gcc.link.dll bin.v2/libs/date_time/build/gcc-4.8/release/debug-symbols-on/threading-multi/libboost_date_time.so.1.56.0
common.copy stage/lib/libboost_date_time.so.1.56.0
ln-UNIX stage/lib/libboost_date_time.so
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/code_conversion.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/attribute_set.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/attribute_value_set.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/severity_level.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/named_scope.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/process_id.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/global_logger_storage.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/thread_id.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/default_attribute_names.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/record_ostream.o
gcc.compile.c++ bin.v2/libs/thread/build/gcc-4.8/release/debug-symbols-on/threading-multi/pthread/thread.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/process_name.o
gcc.link.dll bin.v2/libs/thread/build/gcc-4.8/release/debug-symbols-on/threading-multi/libboost_thread.so.1.56.0
common.copy stage/lib/libboost_thread.so.1.56.0
ln-UNIX stage/lib/libboost_thread.so
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/timer.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/once_block.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/thread_specific.o
...on 100th target...
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/timestamp.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/core.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/text_ostream_backend.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/event.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/threadsafe_queue.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/exceptions.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/trivial.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/unhandled_exception_count.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/dump.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/default_sink.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/dump_ssse3.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/syslog_backend.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/dump_avx2.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/parser_utils.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/spirit_encoding.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/init_from_stream.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/format_parser.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/date_time_format_parser.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/named_scope_format_parser.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/text_file_backend.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/filter_parser.o
gcc.compile.c++ bin.v2/libs/chrono/build/gcc-4.8/release/debug-symbols-on/threading-multi/process_cpu_clocks.o
gcc.link.dll bin.v2/libs/chrono/build/gcc-4.8/release/debug-symbols-on/threading-multi/libboost_chrono.so.1.56.0
common.copy stage/lib/libboost_chrono.so.1.56.0
ln-UNIX stage/lib/libboost_chrono.so
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/settings_parser.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/c_regex_traits.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/formatter_parser.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/cpp_regex_traits.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/fileiter.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/matches_relation_factory.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/regex.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/regex_debug.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/regex_raw_buffer.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/regex_traits_defaults.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/static_mutex.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/w32_regex_traits.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/init_from_settings.o
In file included from ./boost/date_time/gregorian/greg_weekday.hpp:12:0,
from ./boost/date_time/gregorian/greg_calendar.hpp:13,
from ./boost/date_time/gregorian/gregorian_types.hpp:19,
from ./boost/date_time/posix_time/posix_time_config.hpp:18,
from ./boost/date_time/posix_time/posix_time_system.hpp:13,
from ./boost/date_time/posix_time/ptime.hpp:12,
from ./boost/date_time/posix_time/posix_time_types.hpp:12,
from ./boost/thread/thread_time.hpp:11,
from ./boost/thread/lock_types.hpp:18,
from ./boost/thread/lock_algorithms.hpp:11,
from ./boost/thread/locks.hpp:10,
from ./boost/log/sinks/basic_sink_frontend.hpp:32,
from ./boost/log/sinks/unlocked_frontend.hpp:24,
from ./boost/log/sinks.hpp:22,
from libs/log/src/init_from_settings.cpp:45:
./boost/date_time/constrained_value.hpp: In member function âboost::shared_ptr<boost::log::v2_mt_posix::sinks::sink> boost::log::v2_mt_posix::{anonymous}::default_text_file_sink_factory<CharT>::create_sink(const settings_section&) [with CharT = wchar_t; boost::log::v2_mt_posix::{anonymous}::default_text_file_sink_factory<CharT>::settings_section = boost::log::v2_mt_posix::basic_settings_section<wchar_t>]â:
./boost/date_time/constrained_value.hpp:76:7: warning: â*((void*)& day +2)â may be used uninitialized in this function [-Wmaybe-uninitialized]
value_ = value;
^
libs/log/src/init_from_settings.cpp:172:32: note: â*((void*)& day +2)â was declared here
optional< unsigned short > day;
^
libs/log/src/init_from_settings.cpp:249:87: warning: â*((void*)& weekday +4)â may be used uninitialized in this function [-Wmaybe-uninitialized]
return sinks::file::rotation_at_time_point(weekday.get(), hour, minute, second);
^
libs/log/src/init_from_settings.cpp:171:37: note: â*((void*)& weekday +4)â was declared here
optional< date_time::weekdays > weekday;
^
In file included from ./boost/date_time/gregorian/greg_weekday.hpp:12:0,
from ./boost/date_time/gregorian/greg_calendar.hpp:13,
from ./boost/date_time/gregorian/gregorian_types.hpp:19,
from ./boost/date_time/posix_time/posix_time_config.hpp:18,
from ./boost/date_time/posix_time/posix_time_system.hpp:13,
from ./boost/date_time/posix_time/ptime.hpp:12,
from ./boost/date_time/posix_time/posix_time_types.hpp:12,
from ./boost/thread/thread_time.hpp:11,
from ./boost/thread/lock_types.hpp:18,
from ./boost/thread/lock_algorithms.hpp:11,
from ./boost/thread/locks.hpp:10,
from ./boost/log/sinks/basic_sink_frontend.hpp:32,
from ./boost/log/sinks/unlocked_frontend.hpp:24,
from ./boost/log/sinks.hpp:22,
from libs/log/src/init_from_settings.cpp:45:
./boost/date_time/constrained_value.hpp: In member function âboost::shared_ptr<boost::log::v2_mt_posix::sinks::sink> boost::log::v2_mt_posix::{anonymous}::default_text_file_sink_factory<CharT>::create_sink(const settings_section&) [with CharT = char; boost::log::v2_mt_posix::{anonymous}::default_text_file_sink_factory<CharT>::settings_section = boost::log::v2_mt_posix::basic_settings_section<char>]â:
./boost/date_time/constrained_value.hpp:76:7: warning: â*((void*)& day +2)â may be used uninitialized in this function [-Wmaybe-uninitialized]
value_ = value;
^
libs/log/src/init_from_settings.cpp:172:32: note: â*((void*)& day +2)â was declared here
optional< unsigned short > day;
^
libs/log/src/init_from_settings.cpp:249:87: warning: â*((void*)& weekday +4)â may be used uninitialized in this function [-Wmaybe-uninitialized]
return sinks::file::rotation_at_time_point(weekday.get(), hour, minute, second);
^
libs/log/src/init_from_settings.cpp:171:37: note: â*((void*)& weekday +4)â was declared here
optional< date_time::weekdays > weekday;
^
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/wc_regex_traits.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/default_filter_factory.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/usinstances.o
gcc.compile.c++ bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/default_formatter_factory.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/posix_api.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/icu.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/cregex.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/instances.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/wide_posix_api.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/winstances.o
gcc.link.dll bin.v2/libs/regex/build/gcc-4.8/release/debug-symbols-on/threading-multi/libboost_regex.so.1.56.0
common.copy stage/lib/libboost_regex.so.1.56.0
ln-UNIX stage/lib/libboost_regex.so
gcc.link.dll bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/libboost_log.so.1.56.0
common.copy stage/lib/libboost_log.so.1.56.0
ln-UNIX stage/lib/libboost_log.so
gcc.link.dll bin.v2/libs/log/build/gcc-4.8/release/debug-symbols-on/log-api-unix/threading-multi/libboost_log_setup.so.1.56.0
common.copy stage/lib/libboost_log_setup.so.1.56.0
ln-UNIX stage/lib/libboost_log_setup.so
...updated 149 targets...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk