Skip to content

Commit

Permalink
Fix constexpr warnings and constant std::move warnings C26478 C26497.
Browse files Browse the repository at this point in the history
  • Loading branch information
adityamandaleeka committed Oct 8, 2024
1 parent d0e7f8c commit 7aa9be1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ServerErrorHandler : public REQUEST_HANDLER
m_disableStartupPage(disableStartupPage),
m_statusCode(statusCode),
m_subStatusCode(subStatusCode),
m_statusText(std::move(statusText)),
m_statusText(statusText),
m_ExceptionInfoContent(responseContent)
{
}
Expand Down
3 changes: 1 addition & 2 deletions src/Servers/IIS/AspNetCoreModuleV2/DefaultRules.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
<Rule Id="C26475" Action="Error" />
<Rule Id="C26476" Action="None" /> <!-- Expression/symbol 'name' uses a naked union 'union' with multiple type pointers: Use variant instead -->
<Rule Id="C26477" Action="Error" />
<Rule Id="C26478" Action="None" /> <!-- Don't use std::move on constant variables. -->
<Rule Id="C26481" Action="None" /> <!-- Don't use pointer arithmetic. Use span instead -->
<Rule Id="C26482" Action="None" /> <!-- Only index into arrays using constant expressions. -->
<Rule Id="C26483" Action="Error" />
Expand All @@ -95,7 +94,7 @@
<Rule Id="C26494" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize an object. -->
<Rule Id="C26495" Action="None" /> <!-- Variable 'variable' is uninitialized. Always initialize a member variable -->
<Rule Id="C26496" Action="None" /> <!-- The variable 'variable' is assigned only once, mark it as const. -->
<Rule Id="C26497" Action="None" /> <!-- Attempt to make this constexpr -->
<Rule Id="C26497" Action="Error" />
<Rule Id="C26498" Action="Error" />
<Rule Id="C26814" Action="None" /> <!-- The const variable 'variable' can be computed at compile time. Consider using constexpr -->
<Rule Id="C26818" Action="None" /> <!-- Switch statement does not cover all cases. Consider adding a 'default' label -->
Expand Down
36 changes: 18 additions & 18 deletions src/Servers/IIS/AspNetCoreModuleV2/IISLib/hashfn.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
// the low end of the hashtable otherwise. LKRhash applies this internally
// to all hash signatures for exactly this reason.

inline DWORD
inline constexpr DWORD
HashScramble(DWORD dwHash)
{
// Here are 10 primes slightly greater than 10^9
// 1000000007, 1000000009, 1000000021, 1000000033, 1000000087,
// 1000000093, 1000000097, 1000000103, 1000000123, 1000000181.

// default value for "scrambling constant"
const DWORD RANDOM_CONSTANT = 314159269UL;
constexpr DWORD RANDOM_CONSTANT = 314159269UL;
// large prime number, also used for scrambling
const DWORD RANDOM_PRIME = 1000000007UL;
constexpr DWORD RANDOM_PRIME = 1000000007UL;

return (RANDOM_CONSTANT * dwHash) % RANDOM_PRIME ;
}


// Faster scrambling function suggested by Eric Jacobsen

inline DWORD
inline DWORD constexpr
HashRandomizeBits(DWORD dw)
{
return (((dw * 1103515245 + 12345) >> 16)
Expand All @@ -39,7 +39,7 @@ HashRandomizeBits(DWORD dw)


// Small prime number used as a multiplier in the supplied hash functions
const DWORD HASH_MULTIPLIER = 101;
constexpr DWORD HASH_MULTIPLIER = 101;

#undef HASH_SHIFT_MULTIPLY

Expand Down Expand Up @@ -273,51 +273,51 @@ Hash(
}

// Identity hash functions: scalar values map to themselves
inline DWORD Hash(char c)
inline constexpr DWORD Hash(char c)
{ return c; }

inline DWORD Hash(unsigned char uc)
inline constexpr DWORD Hash(unsigned char uc)
{ return uc; }

inline DWORD Hash(signed char sc)
inline constexpr DWORD Hash(signed char sc)
{ return sc; }

inline DWORD Hash(short sh)
inline constexpr DWORD Hash(short sh)
{ return sh; }

inline DWORD Hash(unsigned short ush)
inline constexpr DWORD Hash(unsigned short ush)
{ return ush; }

inline DWORD Hash(int i)
inline constexpr DWORD Hash(int i)
{ return i; }

inline DWORD Hash(unsigned int u)
inline constexpr DWORD Hash(unsigned int u)
{ return u; }

inline DWORD Hash(long l)
inline constexpr DWORD Hash(long l)
{ return l; }

inline DWORD Hash(unsigned long ul)
inline constexpr DWORD Hash(unsigned long ul)
{ return ul; }

inline DWORD Hash(float f)
inline constexpr DWORD Hash(float f)
{
// be careful of rounding errors when computing keys
union {
float f;
DWORD dw;
} u;
} u{};
u.f = f;
return u.dw;
}

inline DWORD Hash(double dbl)
inline constexpr DWORD Hash(double dbl)
{
// be careful of rounding errors when computing keys
union {
double dbl;
DWORD dw[2];
} u;
} u{};
u.dbl = dbl;
return u.dw[0] * HASH_MULTIPLIER + u.dw[1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class StartupExceptionApplication : public InProcessApplicationBase
m_error(errorPageContent),
m_statusCode(statusCode),
m_subStatusCode(subStatusCode),
m_statusText(std::move(statusText)),
m_statusText(statusText),
InProcessApplicationBase(pServer, pApplication)
{
}
Expand Down

0 comments on commit 7aa9be1

Please sign in to comment.