blob: 9de26cf3495809d3e895950274b17c040847a92d [file] [log] [blame]
Ryan Govostesb141b282012-02-11 16:32:09 +00001// RUN: %clang_cc1 -std=c99 -analyze -analyzer-checker=core,experimental.core.BoolAssignment -analyzer-store=region -verify %s
2
3// Test stdbool.h's _Bool
4
5// Prior to C99, stdbool.h uses this typedef, but even in ANSI C mode, _Bool
6// appears to be defined.
7
8// #if __STDC_VERSION__ < 199901L
9// typedef int _Bool;
10// #endif
11
12void test_stdbool_initialization(int y) {
13 if (y < 0) {
14 _Bool x = y; // expected-warning {{Assignment of a non-Boolean value}}
15 return;
16 }
17 if (y > 1) {
18 _Bool x = y; // expected-warning {{Assignment of a non-Boolean value}}
19 return;
20 }
21 _Bool x = y; // no-warning
22}
23
24void test_stdbool_assignment(int y) {
25 _Bool x = 0; // no-warning
26 if (y < 0) {
27 x = y; // expected-warning {{Assignment of a non-Boolean value}}
28 return;
29 }
30 if (y > 1) {
31 x = y; // expected-warning {{Assignment of a non-Boolean value}}
32 return;
33 }
34 x = y; // no-warning
35}