[optional] Warnings about uninitialized values
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_ptrboost::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
On 22.06.2014 00:28, Andrey Semashev wrote:
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:
(...)
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?
Andrey, I'm experiencing the same issue in my code where boost::optional is used quite extensively. Some time ago I found a bug report in GCC's Bugzilla [1] and a StackOverflow thread [2] related to this issue. Additionally, clang doesn't show any warnings in my code. Hence I assumed this is a bug in GCC. It turns out that GCC provides a way to silence such warnings selectively via a #pragma [3]. However, I'm not sure this is the right way to go. WBR, Adam Romanek [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47679 [2] http://stackoverflow.com/questions/21755206/how-to-get-around-gcc-void-b-4-m... [3] http://stackoverflow.com/a/5080980/1776942
On Monday 23 June 2014 08:32:59 Adam Romanek wrote:
On 22.06.2014 00:28, Andrey Semashev wrote:
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:
(...)
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?
Andrey,
I'm experiencing the same issue in my code where boost::optional is used quite extensively.
Some time ago I found a bug report in GCC's Bugzilla [1] and a StackOverflow thread [2] related to this issue. Additionally, clang doesn't show any warnings in my code. Hence I assumed this is a bug in GCC.
Thank you for the links. It seems like this is the compiler bug, although I don't compare optionals in my code. Some other code path must be triggering this problem.
It turns out that GCC provides a way to silence such warnings selectively via a #pragma [3]. However, I'm not sure this is the right way to go.
Yes, but I'm hesitant to silence the warning since it may reveal the actual problems. I'll have to do that though if there's no other solution. PS: I didn't notice there were two options for this, -Wmaybe-uninitialized and -Wuninitialized. Perhaps disabling the former is not that much undesirable.
On Monday 23 June 2014 12:16:17 you wrote:
On Monday 23 June 2014 08:32:59 Adam Romanek wrote:
It turns out that GCC provides a way to silence such warnings selectively via a #pragma [3]. However, I'm not sure this is the right way to go.
Yes, but I'm hesitant to silence the warning since it may reveal the actual problems. I'll have to do that though if there's no other solution.
Unfortunately, a pragma doesn't work in my case - the warning is still generated even though I put the pragma before my code that triggers it. Wrapping boost::optional definition with it also doesn't work.
2014-06-23 10:49 GMT+02:00 Andrey Semashev
On Monday 23 June 2014 12:16:17 you wrote:
On Monday 23 June 2014 08:32:59 Adam Romanek wrote:
It turns out that GCC provides a way to silence such warnings selectively via a #pragma [3]. However, I'm not sure this is the right way to go.
Yes, but I'm hesitant to silence the warning since it may reveal the actual problems. I'll have to do that though if there's no other solution.
Unfortunately, a pragma doesn't work in my case - the warning is still generated even though I put the pragma before my code that triggers it. Wrapping boost::optional definition with it also doesn't work.
Does it help if you change: weekday = date_time::Monday; to weekday = make_optional(date_time::Monday); ? Regards, &rzej
On Monday 23 June 2014 12:47:54 Andrzej Krzemienski wrote:
2014-06-23 10:49 GMT+02:00 Andrey Semashev
: On Monday 23 June 2014 12:16:17 you wrote:
On Monday 23 June 2014 08:32:59 Adam Romanek wrote:
It turns out that GCC provides a way to silence such warnings selectively via a #pragma [3]. However, I'm not sure this is the right way to go.
Yes, but I'm hesitant to silence the warning since it may reveal the
actual
problems. I'll have to do that though if there's no other solution.
Unfortunately, a pragma doesn't work in my case - the warning is still generated even though I put the pragma before my code that triggers it. Wrapping boost::optional definition with it also doesn't work.
Does it help if you change:
weekday = date_time::Monday;
to
weekday = make_optional(date_time::Monday);
?
Yes, looks like it does. It's rather tedious since every such assignment has to be changed.
participants (3)
-
Adam Romanek
-
Andrey Semashev
-
Andrzej Krzemienski