NO

Author Topic: warning #2071: Overflow in constant expression  (Read 5094 times)

mtx500

  • Guest
warning #2071: Overflow in constant expression
« on: March 16, 2005, 04:33:30 PM »
Hi Pelle!

With the newest version (3.00 Beta 4) I get some more
"warning #2071: Overflow in constant expression" messages than before.

I made a small test program to demonstrate the effect:

Code: [Select]
#include <windows.h>

#define CASE_HR(hr) case hr:

void Function(HRESULT hrRet)
{
    switch(hrRet) {
        CASE_HR(E_NOTIMPL)
        CASE_HR(E_NOINTERFACE)
        CASE_HR(E_POINTER)
        CASE_HR(E_ABORT)
        CASE_HR(E_FAIL)
        CASE_HR(E_UNEXPECTED)
            break;
    }
}

// POCCWarn7.c(16): warning #2071: Overflow in constant expression.
// POCCWarn7.c(16): warning #2071: Overflow in constant expression.


I'm compiling this with pocc.exe /O2 /W2 /Ze.

What puzzles me is
a) that the line number of the warning is not correct and
b) that there are two warnings for six identical cases.

Can you make some sense out of that?

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
warning #2071: Overflow in constant expression
« Reply #1 on: March 16, 2005, 07:02:18 PM »
Hello,

I agree, it's confusing.

a) This is because the whole switch statement is parsed before an attempt is made to generate code. It's during code generation that constant folding will trigger a warning. At least not trivial to match expressions to previously parsed source lines. I guess this is why it's not being done today...

b) This has to do with code generation. Several of the values are consecutive, so a jump-table is used (all cases except E_UNEXPECTED). It's the special "use jump-table" code that trigger the warnings.

Pelle
/Pelle