Bug 115648 - Build with GCC 4.8 fails because of -Wmaybe-uninitialized
Summary: Build with GCC 4.8 fails because of -Wmaybe-uninitialized
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andras Becsi
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-06 08:42 PDT by Andras Becsi
Modified: 2013-05-06 11:48 PDT (History)
3 users (show)

See Also:


Attachments
Patch (1.89 KB, patch)
2013-05-06 08:43 PDT, Andras Becsi
no flags Details | Formatted Diff | Diff
Patch (1.54 KB, patch)
2013-05-06 11:44 PDT, Andras Becsi
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andras Becsi 2013-05-06 08:42:43 PDT
Build with GCC 4.8 fails because of -Wmaybe-uninitialized
Comment 1 Andras Becsi 2013-05-06 08:43:19 PDT
Created attachment 200703 [details]
Patch
Comment 2 Mark Hahnenberg 2013-05-06 09:04:42 PDT
Comment on attachment 200703 [details]
Patch

Hmm, maybe there's a way  to make it so OptionRange has a trivial constructor and then we can manually initialize the fields with an init method? I'm leery of disabling warnings.
Comment 3 Michael Saboff 2013-05-06 10:59:22 PDT
I had a trivial constructor but got these messages from clang:

/Volumes/Data/src/webkit.work/Source/JavaScriptCore/runtime/Options.cpp:166:25: error: call to deleted constructor of 'Options::Entry [57]'
Options::Entry Options::s_options[Options::numberOfOptions];
                        ^
In file included from /Volumes/Data/src/webkit.work/Source/JavaScriptCore/runtime/Options.cpp:27:
/Volumes/Data/src/webkit.work/Source/JavaScriptCore/runtime/Options.h:222:12: note: function has been explicitly marked deleted here
    struct Entry {
           ^
1 error generated.

Here is the constructor:
    OptionRange()
        : m_state(Uninitialized)
        , m_rangeString(0)
        , m_lowLimit(0)
        , m_highLimit(0)
    {
    }

What line is it complaining may be uninitialized?
Comment 4 Andras Becsi 2013-05-06 11:44:24 PDT
Created attachment 200731 [details]
Patch
Comment 5 Andras Becsi 2013-05-06 11:44:43 PDT
(In reply to comment #3)
> I had a trivial constructor but got these messages from clang:
> 
> /Volumes/Data/src/webkit.work/Source/JavaScriptCore/runtime/Options.cpp:166:25: error: call to deleted constructor of 'Options::Entry [57]'
> Options::Entry Options::s_options[Options::numberOfOptions];
>                         ^
> In file included from /Volumes/Data/src/webkit.work/Source/JavaScriptCore/runtime/Options.cpp:27:
> /Volumes/Data/src/webkit.work/Source/JavaScriptCore/runtime/Options.h:222:12: note: function has been explicitly marked deleted here
>     struct Entry {
>            ^
> 1 error generated.
> 
> Here is the constructor:
>     OptionRange()
>         : m_state(Uninitialized)
>         , m_rangeString(0)
>         , m_lowLimit(0)
>         , m_highLimit(0)
>     {
>     }

The problem with this is that a constructor with an initializer-list is not trivial any more and hence can not be placed into a union,which can only hold POD.
With "trivial constructor" I actually meant "default constructor with no initializer list and empty body" (equivalent with an implicitly-declared constructor generated by the compiler).

GCC has an informative error message with the above constructor:

error: member 'JSC::OptionRange JSC::Options::Entry::<anonymous union>::optionRangeVal' with constructor not allowed in union
note: unrestricted unions only available with -std=c++11 or -std=gnu++11

> 
> What line is it complaining may be uninitialized?

/home/abecsi/devel/git/webkit-git-svn/Source/JavaScriptCore/runtime/Options.cpp:120:17: error: 'value.JSC::OptionRange::m_state' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This is actually valid, since in Options::setOption the values are not initialized, hence the new patch.
Comment 6 Andras Becsi 2013-05-06 11:48:23 PDT
Comment on attachment 200731 [details]
Patch

Clearing flags on attachment: 200731

Committed r149622: <http://trac.webkit.org/changeset/149622>
Comment 7 Andras Becsi 2013-05-06 11:48:28 PDT
All reviewed patches have been landed.  Closing bug.