diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-05 17:18:09 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-11-05 17:18:09 +0000 |
commit | 8f57cb0305232cb53fff00ef151ca716766f3437 (patch) | |
tree | 8b316eca843681b024034db1125707173b9adb4a /test/SemaCXX | |
parent | 51fb8b013e7734b795139f49d3b1f77c539be20a (diff) |
Notes
Diffstat (limited to 'test/SemaCXX')
-rw-r--r-- | test/SemaCXX/compare.cpp | 15 | ||||
-rw-r--r-- | test/SemaCXX/conditional-expr.cpp | 22 | ||||
-rw-r--r-- | test/SemaCXX/constructor-initializer.cpp | 33 | ||||
-rw-r--r-- | test/SemaCXX/overload-member-call.cpp | 12 | ||||
-rw-r--r-- | test/SemaCXX/overloaded-operator.cpp | 11 | ||||
-rw-r--r-- | test/SemaCXX/primary-base.cpp | 4 |
6 files changed, 93 insertions, 4 deletions
diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp new file mode 100644 index 000000000000..806b078e8df6 --- /dev/null +++ b/test/SemaCXX/compare.cpp @@ -0,0 +1,15 @@ +// RUN: clang-cc -fsyntax-only -pedantic -verify %s + +int test0(long a, unsigned long b) { + enum Enum {B}; + return (a == B) + // expected-warning {{comparison of integers of different signs}} + ((int)a == B) + // expected-warning {{comparison of integers of different signs}} + ((short)a == B) + // expected-warning {{comparison of integers of different signs}} + (a == (unsigned int) B) + // expected-warning {{comparison of integers of different signs}} + (a == (unsigned short) B); // expected-warning {{comparison of integers of different signs}} + + // Should be able to prove all of these are non-negative. + return (b == (long) B) + + (b == (int) B) + + (b == (short) B); +} diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp index fea3324b5fd5..da2dd67d061d 100644 --- a/test/SemaCXX/conditional-expr.cpp +++ b/test/SemaCXX/conditional-expr.cpp @@ -156,8 +156,8 @@ void test() i1 = i1 ? i1 : ir1; int *pi1 = i1 ? &i1 : 0; pi1 = i1 ? 0 : &i1; - i1 = i1 ? i1 : EVal; - i1 = i1 ? EVal : i1; + i1 = i1 ? i1 : EVal; // expected-warning {{operands of ? are integers of different signs}} ?? + i1 = i1 ? EVal : i1; // expected-warning {{operands of ? are integers of different signs}} ?? d1 = i1 ? 'c' : 4.0; d1 = i1 ? 4.0 : 'c'; Base *pb = i1 ? (Base*)0 : (Derived*)0; @@ -177,6 +177,24 @@ void test() (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}} (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}} + + unsigned long test0 = 5; + test0 = test0 ? (long) test0 : test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? (int) test0 : test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? (short) test0 : test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? test0 : (long) test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? test0 : (int) test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? test0 : (short) test0; // expected-warning {{operands of ? are integers of different signs}} + test0 = test0 ? test0 : (long) 10; + test0 = test0 ? test0 : (int) 10; + test0 = test0 ? test0 : (short) 10; + test0 = test0 ? (long) 10 : test0; + test0 = test0 ? (int) 10 : test0; + test0 = test0 ? (short) 10 : test0; + + test0 = test0 ? EVal : test0; + test0 = test0 ? EVal : (int) test0; // expected-warning {{operands of ? are integers of different signs}} + // Note the thing that this does not test: since DR446, various situations // *must* create a separate temporary copy of class objects. This can only // be properly tested at runtime, though. diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index b86a27d66d98..20cf35b293b6 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -122,3 +122,36 @@ struct Q { float *pf; }; + +// A silly class used to demonstrate field-is-uninitialized in constructors with +// multiple params. +class TwoInOne { TwoInOne(TwoInOne a, TwoInOne b) {} }; +class InitializeUsingSelfTest { + bool A; + char* B; + int C; + TwoInOne D; + InitializeUsingSelfTest(int E) + : A(A), // expected-warning {{field is uninitialized when used here}} + B((((B)))), // expected-warning {{field is uninitialized when used here}} + C(A && InitializeUsingSelfTest::C), // expected-warning {{field is uninitialized when used here}} + D(D, // expected-warning {{field is uninitialized when used here}} + D) {} // expected-warning {{field is uninitialized when used here}} +}; + +int IntWrapper(int i) { return 0; }; +class InitializeUsingSelfExceptions { + int A; + int B; + InitializeUsingSelfExceptions(int B) + : A(IntWrapper(A)), // Due to a conservative implementation, we do not report warnings inside function/ctor calls even though it is possible to do so. + B(B) {} // Not a warning; B is a local variable. +}; + +class CopyConstructorTest { + bool A, B, C; + CopyConstructorTest(const CopyConstructorTest& rhs) + : A(rhs.A), + B(B), // expected-warning {{field is uninitialized when used here}} + C(rhs.C || C) { } // expected-warning {{field is uninitialized when used here}} +}; diff --git a/test/SemaCXX/overload-member-call.cpp b/test/SemaCXX/overload-member-call.cpp index 96e570da654b..937b65d633f9 100644 --- a/test/SemaCXX/overload-member-call.cpp +++ b/test/SemaCXX/overload-member-call.cpp @@ -54,3 +54,15 @@ void test(X x, const X xc, X* xp, const X* xcp, volatile X xv, volatile X* xvp) X::h(0); // expected-error{{call to non-static member function without an object argument}} } + +struct X1 { + int& member(); + float& member() const; +}; + +struct X2 : X1 { }; + +void test_X2(X2 *x2p, const X2 *cx2p) { + int &ir = x2p->member(); + float &fr = cx2p->member(); +} diff --git a/test/SemaCXX/overloaded-operator.cpp b/test/SemaCXX/overloaded-operator.cpp index 0f723ad206b9..750038d4ab51 100644 --- a/test/SemaCXX/overloaded-operator.cpp +++ b/test/SemaCXX/overloaded-operator.cpp @@ -268,3 +268,14 @@ void circ() { CircA a; a->val = 0; // expected-error {{circular pointer delegation detected}} } + +// PR5360: Arrays should lead to built-in candidates for subscript. +typedef enum { + LastReg = 23, +} Register; +class RegAlloc { + int getPriority(Register r) { + return usepri[r]; + } + int usepri[LastReg + 1]; +}; diff --git a/test/SemaCXX/primary-base.cpp b/test/SemaCXX/primary-base.cpp index 62f9087bd91d..a7e18bd528a1 100644 --- a/test/SemaCXX/primary-base.cpp +++ b/test/SemaCXX/primary-base.cpp @@ -4,8 +4,8 @@ class B : virtual A { }; class C : B { }; -// Since A is already a primary base class, C should be the primary base class of F. +// Since A is already a primary base class, C should be the primary base class +// of F. class F : virtual A, virtual C { }; int sa[sizeof(F) == sizeof(A) ? 1 : -1]; - |