ValhallaTeam / angleproject

Automatically exported from code.google.com/p/angleproject
Other
0 stars 0 forks source link

ValidateLimitations.cpp does not compile with -Wshorten-64-to-32 #405

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile ANGLE with clang with -Wshorten-64-to-32 warning enabled.

What is the expected output? What do you see instead?
Expected no warnings.  Got warnings.

What version of the product are you using? On what operating system?
ANGLE r1641 merged into the WebKit project.

Please provide any additional information below.

Source/ThirdParty/ANGLE/src/compiler/ValidateLimitations.cpp:434:30: error: 
implicit conversion loses integer precision: 'TIntermSequence::size_type' (aka 
'unsigned long') to 'value_type' (aka 'int') [-Werror,-Wshorten-64-to-32]
            pIndex.push_back(i);
            ~~~~~~           ^
1 error generated.

This happens because ParamIndex is typedef-ed to std::vector<int>, but 
TIntermSequence::size_type is a size_t type:

    typedef std::vector<int> ParamIndex;
    ParamIndex pIndex;
    TIntermSequence& params = node->getSequence();
    for (TIntermSequence::size_type i = 0; i < params.size(); ++i) {
            [...]
            pIndex.push_back(i);

Changing ParamIndex to:

    typedef std::vector<size_t> ParamIndex;

causes this issue later:

Source/ThirdParty/ANGLE/src/compiler/ValidateLimitations.cpp:451:54: error: 
implicit conversion loses integer precision: 'const unsigned long' to 'int' 
[-Werror,-Wshorten-64-to-32]
        const TParameter& param = function->getParam(*i);
                                  ~~~~~~~~           ^~
1 error generated.

The getParam() method can be changed to use size_t:

     int getParamCount() const { return static_cast<int>(parameters.size()); }  
-    const TParameter& getParam(int i) const { return parameters[i]; }
+    const TParameter& getParam(size_t i) const { return parameters[i]; }

However, there are other places where getParam() is passed an int (although 
that doesn't trigger a warning).

Original issue reported on code.google.com by ddkilzer@gmail.com on 27 Jan 2013 at 3:29

GoogleCodeExporter commented 9 years ago

Original comment by kbr@chromium.org on 7 Feb 2013 at 1:13

GoogleCodeExporter commented 9 years ago

Original comment by kbr@chromium.org on 7 Feb 2013 at 1:31

GoogleCodeExporter commented 9 years ago
Fixed in https://code.google.com/p/angleproject/source/detail?r=1826 .

Original comment by kbr@chromium.org on 12 Feb 2013 at 3:10