From ecda6fb71288b1dc3b70ade0c8c75db26ceb1426 Mon Sep 17 00:00:00 2001 From: John McCall Date: Tue, 13 Jul 2010 06:26:23 +0000 Subject: [PATCH] Check in this -Wconversion C++ test case that's been sitting on my machine for awhile. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108232 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/SemaCXX/conversion.cpp | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/SemaCXX/conversion.cpp diff --git a/test/SemaCXX/conversion.cpp b/test/SemaCXX/conversion.cpp new file mode 100644 index 0000000000..f648943807 --- /dev/null +++ b/test/SemaCXX/conversion.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion -verify %s + +typedef signed char int8_t; +typedef signed short int16_t; +typedef signed int int32_t; +typedef signed long int64_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +typedef unsigned long uint64_t; + +// +namespace test0 { + int32_t test1_positive(char *I, char *E) { + return (E - I); // expected-warning {{implicit conversion loses integer precision}} + } + + int32_t test1_negative(char *I, char *E) { + return static_cast(E - I); + } + + uint32_t test2_positive(uint64_t x) { + return x; // expected-warning {{implicit conversion loses integer precision}} + } + + uint32_t test2_negative(uint64_t x) { + return (uint32_t) x; + } +} + +namespace test1 { + uint64_t test1(int x, unsigned y) { + return sizeof(x == y); + } + + uint64_t test2(int x, unsigned y) { + return __alignof(x == y); + } + + void * const foo(); + bool test2(void *p) { + return p == foo(); + } +}