diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-04-22 10:21:45 +0000 |
---|---|---|
committer | <> | 2015-04-25 21:44:09 +0000 |
commit | f80b5ea1605c9f9408c5aa386ba71c16d918ebbf (patch) | |
tree | bb7eafaa81fc4b8c5c215bc08d517fd158db234a /gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C | |
parent | c27a97d04853380f1e80525391b3f0d156ed4c84 (diff) | |
download | gcc-tarball-f80b5ea1605c9f9408c5aa386ba71c16d918ebbf.tar.gz |
Imported from /home/lorry/working-area/delta_gcc-tarball/gcc-5.1.0.tar.bz2.gcc-5.1.0
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C')
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C new file mode 100644 index 0000000000..414a0dacf9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C @@ -0,0 +1,65 @@ +// PR c++/65642 +// { dg-do compile { target c++11 } } + +// Check we're able to evaluate these. + +#define SA(X) static_assert((X),#X) + +constexpr char s[] = "abc"; +constexpr int t[] = { 'a', 'b', 'c', '\0' }; + +constexpr char +fn1 (const char *p) +{ + return *(p + 1); +} + +constexpr char +fn2 (const char *p) +{ + return p[1]; +} + +constexpr int +fn3 (const int *p) +{ + return *(p + 1); +} + +constexpr int +fn4 (const int *p) +{ + return p[1]; +} + +constexpr auto c1 = fn1 (&s[0]); +constexpr auto c2 = fn1 (&s[1]); +constexpr auto c3 = fn1 (&s[2]); + +SA (c1 == 'b'); +SA (c2 == 'c'); +SA (c3 == '\0'); + +constexpr auto d1 = fn2 (&s[0]); +constexpr auto d2 = fn2 (&s[1]); +constexpr auto d3 = fn2 (&s[2]); + +SA (d1 == 'b'); +SA (d2 == 'c'); +SA (d3 == '\0'); + +constexpr auto e1 = fn3 (&t[0]); +constexpr auto e2 = fn3 (&t[1]); +constexpr auto e3 = fn3 (&t[2]); + +SA (e1 == 'b'); +SA (e2 == 'c'); +SA (e3 == '\0'); + +constexpr auto f1 = fn4 (&t[0]); +constexpr auto f2 = fn4 (&t[1]); +constexpr auto f3 = fn4 (&t[2]); + +SA (f1 == 'b'); +SA (f2 == 'c'); +SA (f3 == '\0'); |