diff options
author | Guillaume Chatelet <gchatelet@google.com> | 2018-11-26 16:25:55 +0000 |
---|---|---|
committer | Guillaume Chatelet <gchatelet@google.com> | 2018-11-26 16:25:55 +0000 |
commit | 10a7ee704417a9af6150c574f32befc32c3e2182 (patch) | |
tree | 1136a948215962280fa959da065ba6aed8d2d741 /clang-tools-extra/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp | |
parent | b9e4852c92c0fb5cf3ab21d5a9ef3805758233b8 (diff) | |
download | bcm5719-llvm-10a7ee704417a9af6150c574f32befc32c3e2182.tar.gz bcm5719-llvm-10a7ee704417a9af6150c574f32befc32c3e2182.zip |
[clang-tidy] Improving narrowing conversions
Summary:
Newly flagged narrowing conversions:
- integer to narrower signed integer (this is compiler implementation defined),
- integer - floating point narrowing conversions,
- floating point - integer narrowing conversions,
- constants with narrowing conversions (even in ternary operator).
Reviewers: hokein, alexfh, aaron.ballman, JonasToth
Reviewed By: aaron.ballman, JonasToth
Subscribers: lebedev.ri, courbet, nemanjai, xazax.hun, kbarton, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D53488
llvm-svn: 347570
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp new file mode 100644 index 00000000000..f28985d2f31 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/cppcoreguidelines-narrowing-conversions-pedanticmode-option.cpp @@ -0,0 +1,23 @@ +// RUN: %check_clang_tidy %s cppcoreguidelines-narrowing-conversions %t \ +// RUN: -config="{CheckOptions: [ \ +// RUN: {key: "cppcoreguidelines-narrowing-conversions.PedanticMode", value: 1} \ +// RUN: ]}" \ +// RUN: -- -target x86_64-unknown-linux -fsigned-char + +namespace floats { + +void triggers_wrong_constant_type_warning(double d) { + int i = 0.0; + // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: constant value should be of type of type 'int' instead of 'double' [cppcoreguidelines-narrowing-conversions] + i += 2.0; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constant value should be of type of type 'int' instead of 'double' [cppcoreguidelines-narrowing-conversions] + i += 2.0f; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: constant value should be of type of type 'int' instead of 'float' [cppcoreguidelines-narrowing-conversions] +} + +void triggers_narrowing_warning_when_overflowing() { + unsigned short us = 65537.0; + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: narrowing conversion from constant 'double' to 'unsigned short' [cppcoreguidelines-narrowing-conversions] +} + +} // namespace floats |