[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / constant-conversion.cpp
blob9be8b139e79e228bde758394b2cc0bd7a7be8b99
1 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin %s
3 // This file tests -Wconstant-conversion, a subcategory of -Wconversion
4 // which is on by default.
6 constexpr int nines() { return 99999; }
8 void too_big_for_char(int param) {
9 char warn1 = false ? 0 : 99999;
10 // expected-warning@-1 {{implicit conversion from 'int' to 'char' changes value from 99999 to -97}}
11 char warn2 = false ? 0 : nines();
12 // expected-warning@-1 {{implicit conversion from 'int' to 'char' changes value from 99999 to -97}}
14 char warn3 = param > 0 ? 0 : 99999;
15 // expected-warning@-1 {{implicit conversion from 'int' to 'char' changes value from 99999 to -97}}
16 char warn4 = param > 0 ? 0 : nines();
17 // expected-warning@-1 {{implicit conversion from 'int' to 'char' changes value from 99999 to -97}}
19 char ok1 = true ? 0 : 99999;
20 char ok2 = true ? 0 : nines();
22 char ok3 = true ? 0 : 99999 + 1;
23 char ok4 = true ? 0 : nines() + 1;
26 void test_bitfield() {
27 struct S {
28 int one_bit : 1;
29 } s;
31 s.one_bit = 1; // expected-warning {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}
32 s.one_bit = true; // no-warning