Dieter
Dieter

Reputation: 53

Cannot get rid of warning C4554

This code always produces a C4554 warning when compiling in Visual Studio 2015. However, g++ (on Coliru) compiles it without warnings. The warning message is:

warning C4554: '<<': check operator precedence for possible error; use parentheses to clarify precedence

According to this, operator- takes precedence over operator<<. So the parentheses shouldn't be even required. (Omitting them gives the same warning.) Can someone tell me reason for this warning, or how to get rid of it?

#include <array>

template<int C>
void F(std::array<int, 2 << (C-1)> const&) // 2 << (2-1) = 4
{
}

int main()
{
    std::array<int,4> arr;
    F<2>(arr);
}

Upvotes: 5

Views: 1905

Answers (2)

user4832129
user4832129

Reputation:

You may try this:

constexpr std::size_t calc_size(int param)
{
    return 2 << (param - 1);
}

template<int C>
void F(std::array<int, calc_size(C)> const&) // 2 << (2-1) = 4
{
} 

Upvotes: 4

Software_Designer
Software_Designer

Reputation: 8587

In Visual Studio 2015, use #pragma warning( disable : C4554 ) to disable the specified warning message. However, It is not wise to disable warning messages though.

More documentation here... https://msdn.microsoft.com/en-us/library/aa273936(v=vs.60).aspx

See this link to see why the warning C4554 appears... https://msdn.microsoft.com/en-us/library/5d2e57c5.aspx

Upvotes: -1

Related Questions