diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-02 01:16:57 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-02-02 01:16:57 +0000 |
| commit | 84f6dcf2b52c2cfc8cb69e66175623a6285a43e1 (patch) | |
| tree | 108c8489abbd94e2cf4efa8ed21d706b8073ebdb /clang/test/SemaCXX/constant-expression-cxx11.cpp | |
| parent | dc51a5d8f3e19d94bd9677b5c4967507877f89c2 (diff) | |
| download | bcm5719-llvm-84f6dcf2b52c2cfc8cb69e66175623a6285a43e1.tar.gz bcm5719-llvm-84f6dcf2b52c2cfc8cb69e66175623a6285a43e1.zip | |
constexpr:
* support the gcc __builtin_constant_p() ? ... : ... folding hack in C++11
* check for unspecified values in pointer comparisons and pointer subtractions
llvm-svn: 149578
Diffstat (limited to 'clang/test/SemaCXX/constant-expression-cxx11.cpp')
| -rw-r--r-- | clang/test/SemaCXX/constant-expression-cxx11.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp index 5a05cf3c781..36736ad297c 100644 --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -37,6 +37,7 @@ namespace DerivedToVBaseCast { D d; constexpr B *p = &d; constexpr C *q = &d; + static_assert((void*)p != (void*)q, ""); static_assert((A*)p == (A*)q, ""); static_assert((Aa*)p != (Aa*)q, ""); @@ -65,7 +66,6 @@ namespace DerivedToVBaseCast { struct Z : Y1, Y2 {}; Z z; static_assert((X*)(Y1*)&z != (X*)(Y2*)&z, ""); - } namespace ConstCast { @@ -666,7 +666,7 @@ static_assert(&bot1 != &bot2, ""); constexpr Bottom *pb1 = (Base*)&derived; constexpr Bottom *pb2 = (Base2*)&derived; -static_assert(pb1 != pb2, ""); +static_assert(&pb1 != &pb2, ""); static_assert(pb1 == &bot1, ""); static_assert(pb2 == &bot2, ""); @@ -1113,3 +1113,17 @@ namespace IndirectField { static_assert(s2.e == 0, ""); // expected-error {{constant expression}} expected-note {{union with active member}} static_assert(s2.f == 7, ""); } + +namespace Fold { + + // This macro forces its argument to be constant-folded, even if it's not + // otherwise a constant expression. + #define fold(x) (__builtin_constant_p(x) ? (x) : (x)) + + constexpr int n = (int)(char*)123; // expected-error {{constant expression}} expected-note {{reinterpret_cast}} + constexpr int m = fold((int)(char*)123); // ok + static_assert(m == 123, ""); + + #undef fold + +} |

