Does Clang not report uninitialized variables in C ++?

I understand that local variables are not automatically initialized in C ++, so you should always assign a value to them before using them. However, at least in simple cases, the compiler should warn you if you forget it. I rely more or less on this article .

Given this program, I expect to receive a warning when sending xto std::out...

#include <iostream>

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

  int x;
  std::cout << x;

  return 0;
}

... but the warning does not appear. If, however, I run the static analyzer, I get the expected warning: the function call argument is an uninitialized value.

I compile and run using Xcode 5.1 using the Apple LLVM 5.1 compiler. I use the standard build settings from the Xcode command-line project template (C ++), language dialects are installed on GNU99 (for C) and GNU ++ 11 (C ++).

The Uninitialized Variables parameter is set to Yes (Aggressive) ( -Wconditional-uninitialized). Switching only to Yes ( -Wuninitialized) causes a warning: when used here, the variable "x" is not initialized. Question Part 1: Why is the warning not displayed with the default setting ( -Wconditional-uninitialized)? The documentation in Xcode shows that the aggressive version detects more problems:

() , , .

, , 0, - . 2: ?

+4
1

1) ?

clang -Wall . -, Apple , -Wall ( ), , .

, , , , . ++ , , : -)

-Wall, .

2) ?

-, , " undefined". , , , - . , - , , .

, , (, ). , . , youtube, , .

, : -)

+6

Source: https://habr.com/ru/post/1532566/


All Articles