Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Windows equivalent of -Wuninitialized

erling_andersen
New Contributor I
1,063 Views

How do I do the equivalent of -Wuninitialized on Windows?

Also I would like to make the usage of unitialized and error. Can I do that?

 

0 Kudos
13 Replies
Judith_W_Intel
Employee
1,062 Views

 

Should be:

/Qdiag-warning:592

Although it looks like this warning is enabled on Windows by default so I think  the above is unnecessary.

If you want it to be an error use /Qdiag-error:592.

Judy

 

0 Kudos
TimP
Honored Contributor III
1,062 Views

/check includes /check:uninit (a warning) by default, but otherwise it's not on by default.  Note the colon required on Windows, not on linux.

0 Kudos
Judith_W_Intel
Employee
1,062 Views

 

The /check:uninit option is a bit different -- That enables runtime checking of uninitialized variables, not compile time diagnostics.

So it's not the equivalent of -Wuninitialized.

Judy

0 Kudos
erling_andersen
New Contributor I
1,062 Views

To me it seems that  /Qdiag-error:592.do not work. Even though I had an unitialized variable no warning or no error was displayed. Below is my compile line.

icl -DCALL_CPU_INTEL_P4 /Oa /DSYSTHREADING=1 /DSYSPTHREAD=1 -DBLDTOOL_INTELC -DWIN64X86=1 -D_CPU_GENERIC_ /D_CRT_SECURE_NO_DEPRECATE /Qvc9 /Qlocation,link,"c:\Program Files (X86)\Microsoft Visual Studio 9.0\VC\bin" /W1 /Wcheck /Qdiag-error:592 /GF /DSYSRESTRICT /Qrestrict /Qprec_div /Qdiag-disable:1572,177 -DSYSMT /MTd /ZI /debug:minimal /Ge /Ob0 /Qfp-stack-check /Zi -DSYSRELEASE=10 -DSYSDEBUG=10 -D_MOSEKDEV=10 -DCCVERSION=15.0.1 /Isrc\basic /Isrc\cpub /Isrc\dualize /Isrc\homo /Isrc\kfac /Isrc\lalib /Isrc\lu /Isrc\math /Isrc\misc /Isrc\netopt /Isrc\network /Isrc\optimize /Isrc\order /Isrc\pivot /Isrc\prslv /Isrc\simplex /Isrc\temp /Isrc\thread /Isrc\cmio\extern /Ibld\bogense\debug\default\intelc-15.0.1\src\ivec /Isrc\lalib /Isrc\lalib\common /c src\math\spchol.c /Fobld\bogense\debug\default\intelc-15.0.1\bin\runchol-objs\spchol.obj
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.1.148 Build 20141023
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

 

0 Kudos
Judith_W_Intel
Employee
1,062 Views

 

Can you please provide a small code sample showing the use of the uninitialized variable?

thanks

Judy

0 Kudos
KitturGanesh
Employee
1,062 Views

The example below works fine like Judy mentions, so a test case showing the problem is needed.....

----------------------------------
%type uninit.cpp
#include <stdio.h>

int main()
{
    int x;
    printf("%d\n", x);
    return 0;
}

%icl uninit.cpp
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Ve
rsion 15.0.1.148 Build 20141023
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

uninit.cpp
uninit.cpp(6): warning #592: variable "x" is used before its value is set
      printf("%d\n", x);
                     ^

Microsoft (R) Incremental Linker Version 12.00.30723.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:uninit.exe
uninit.obj

%icl /Qdiag-error:592 uninit.cpp
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Ve
rsion 15.0.1.148 Build 20141023
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

uninit.cpp
uninit.cpp(6): error #592: variable "x" is used before its value is set
      printf("%d\n", x);
                     ^
-----------------------------------

0 Kudos
erling_andersen
New Contributor I
1,062 Views

I agree it works on your example. I tried the capabilities on my source and it did not seem to work. Maybe I did something wrong.

I will get back if I can produce an example where it does not work.

 

 

0 Kudos
KitturGanesh
Employee
1,062 Views

Sure, thanks for letting us know. If you're able to get a reproducer that will be great as it'll be interesting why it doesn't in your environment. That said, you can use the -P option to create a .i (pre-processed) file and attach to this issue if you're able to create a test reproducer.

_Kittur 

0 Kudos
KitturGanesh
Employee
1,062 Views

Any luck in creating a test reproducer?

0 Kudos
erling_andersen
New Contributor I
1,062 Views
You do not discover that b is uninitialiazed for c>1. Maybe that is too tricky for you discover. 


#include <stdio.h>

void test(int c)
{
  int b=0;

  printf("c=%d\n",c);	


   if ( c>1 ) 
   {
   	 int b=1;

   	 printf("pelle\n");

   	 b += 2*c;
   }
   else
   {
     printf("polle");	 

      b += c;
    }
     
    printf("b=%d\n",b);
  }


int main(int argc,char *argv[])
{

  test(atoi(argv[0]));

}

 

0 Kudos
Judith_W_Intel
Employee
1,062 Views

 

Are you sure you posted the right example? It looks like the b inside test() is unconditionalized initialized to 0 at the top of test().

And the local b inside the first if is initialized to 1. There's no declaration of b without an initialization.

Judy

0 Kudos
erling_andersen
New Contributor I
1,062 Views

You totally right. I will get back if I find an example.

0 Kudos
KitturGanesh
Employee
1,062 Views

That's correct @Anderson. I just tried the example as well and couldn't reproduce. Thanks for trying and getting us a test reproducer. It'll be an interesting case if we can reproduce the issue, appreciate much.

_Kittur 

0 Kudos
Reply