diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-12 12:46:16 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2011-12-12 12:46:16 +0000 |
commit | 6d6ecc34f841df7f697100c221ed6af814844dbf (patch) | |
tree | 1e5528d2227b3b70a5c68ec4740dcae0dff27e09 /clang/test/SemaCXX/constant-expression-cxx11.cpp | |
parent | 6b0e34c445683bff74b7441a2c09d4730c264fb4 (diff) | |
download | bcm5719-llvm-6d6ecc34f841df7f697100c221ed6af814844dbf.tar.gz bcm5719-llvm-6d6ecc34f841df7f697100c221ed6af814844dbf.zip |
Implement C++11 constant expression cast restrictions.
llvm-svn: 146371
Diffstat (limited to 'clang/test/SemaCXX/constant-expression-cxx11.cpp')
-rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx11.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index 3ba87b3d91e..55762b4ea4c 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i686-linux -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -triple i686-linux -fsyntax-only -verify -std=c++11 -pedantic %s -Wno-comment namespace StaticAssertFoldTest { @@ -165,7 +165,7 @@ namespace FunctionCast { constexpr int f() { return 1; } typedef double (*DoubleFn)(); typedef int (*IntFn)(); - int a[(int)DoubleFn(f)()]; // expected-error {{variable length array}} + int a[(int)DoubleFn(f)()]; // expected-error {{variable length array}} expected-warning{{extension}} int b[(int)IntFn(f)()]; // ok } @@ -297,6 +297,31 @@ constexpr S* sptr = &s; // test elsewhere. constexpr bool dyncast = sptr == dynamic_cast<S*>(sptr); +struct Str { + // FIXME: In C++ mode, we should say 'integral' not 'integer' + int a : dynamic_cast<S*>(sptr) == dynamic_cast<S*>(sptr); // \ + expected-warning {{not integer constant expression}} \ + expected-note {{dynamic_cast not allowed in a constant expression}} + int b : reinterpret_cast<S*>(sptr) == reinterpret_cast<S*>(sptr); // \ + expected-warning {{not integer constant expression}} \ + expected-note {{reinterpret_cast not allowed in a constant expression}} + int c : (S*)(long)(sptr) == (S*)(long)(sptr); // \ + expected-warning {{not integer constant expression}} \ + expected-note {{reinterpreting cast not allowed in a constant expression}} + int d : (S*)(42) == (S*)(42); // \ + expected-warning {{not integer constant expression}} \ + expected-note {{reinterpreting cast not allowed in a constant expression}} + int e : (Str*)(sptr) == (Str*)(sptr); // \ + expected-warning {{not integer constant expression}} \ + expected-note {{reinterpreting cast not allowed in a constant expression}} + int f : &(Str&)(*sptr) == &(Str&)(*sptr); // \ + expected-warning {{not integer constant expression}} \ + expected-note {{reinterpreting cast not allowed in a constant expression}} + int g : (S*)(void*)(sptr) == sptr; // \ + expected-warning {{not integer constant expression}} \ + expected-note {{reinterpreting cast not allowed in a constant expression}} +}; + extern char externalvar[]; // FIXME: This is not a constant expression; check we reject this and move this // test elsewhere. @@ -414,7 +439,7 @@ static_assert((&zs[0][0][0][2])[-1] == 2, ""); static_assert(**(**(zs + 1) + 1) == 11, ""); static_assert(*(&(&(*(*&(&zs[2] - 1)[0] + 2 - 2))[2])[-1][-1] + 1) == 11, ""); -constexpr int arr[40] = { 1, 2, 3, [8] = 4 }; +constexpr int arr[40] = { 1, 2, 3, [8] = 4 }; // expected-warning {{extension}} constexpr int SumNonzero(const int *p) { return *p + (*p ? SumNonzero(p+1) : 0); } @@ -677,7 +702,7 @@ union U { int b; }; -constexpr U u[4] = { { .a = 0 }, { .b = 1 }, { .a = 2 }, { .b = 3 } }; +constexpr U u[4] = { { .a = 0 }, { .b = 1 }, { .a = 2 }, { .b = 3 } }; // expected-warning 4{{extension}} static_assert(u[0].a == 0, ""); static_assert(u[0].b, ""); // expected-error {{constant expression}} static_assert(u[1].b == 1, ""); |