diff options
author | Martin Sebor <msebor@redhat.com> | 2016-03-15 03:05:17 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2016-03-14 21:05:17 -0600 |
commit | 3ea33585de3d2b26f65dab8df27b5046981964a7 (patch) | |
tree | b05cf8fc1e8c4f2b0f08902a4ac834acc5e6c6a5 /gcc | |
parent | 08a1cadc10b80f76033d18a8a2b6dfac53926bdc (diff) | |
download | gcc-3ea33585de3d2b26f65dab8df27b5046981964a7.zip gcc-3ea33585de3d2b26f65dab8df27b5046981964a7.tar.gz gcc-3ea33585de3d2b26f65dab8df27b5046981964a7.tar.bz2 |
PR c++/53792 - [C++11] improving compiler-time constexpr evaluation
gcc/testsuite/ChangeLog:
2016-03-14 Martin Sebor <msebor@redhat.com>
PR c++/53792
* g++.dg/cpp0x/constexpr-inline.C: New test.
* g++.dg/cpp0x/constexpr-inline-1.C: Same.
From-SVN: r234208
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-inline-1.C | 29 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-inline.C | 40 |
3 files changed, 75 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d9015bb..e9b0a9a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-03-14 Martin Sebor <msebor@redhat.com> + + PR c++/53792 + * g++.dg/cpp0x/constexpr-inline.C: New test. + * g++.dg/cpp0x/constexpr-inline-1.C: Same. + 2016-03-14 David Edelsohn <dje.gcc@gmail.com> * gcc.dg/torture/pr70083.c: Prune non-standard ABI. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-inline-1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-inline-1.C new file mode 100644 index 0000000..fed6990 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-inline-1.C @@ -0,0 +1,29 @@ +// PR c++/53792 - [C++11] improving compiler-time constexpr evaluation +// Test case from comment #8. +// { dg-do compile { target c++14 } } +// { dg-additional-options "-O1 -fdump-tree-optimized" } + +template <class T> +void sink (T); + +constexpr unsigned foo () +{ + unsigned i = 1; + while ((i << 1) > i) + i = i << 1; + + return i; +} + +template <unsigned N> +struct S { }; + +void bar () +{ + sink (foo ()); + sink (S<foo ()>()); +} + +// Verify that the call to the foo() constexpr function is inlined +// regardless of whether or not it's invoked in a constant expression. +// { dg-final { scan-tree-dump-not "= *foo *\\\(" "optimized" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-inline.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-inline.C new file mode 100644 index 0000000..d04257c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-inline.C @@ -0,0 +1,40 @@ +// PR c++/53792 - [C++11] improving compiler-time constexpr evaluation +// { dg-do compile { target c++11 } } +// { dg-additional-options "-O1 -fdump-tree-optimized" } + +struct entry +{ + char const* label; + int value; +}; + +constexpr bool same (char const *x, char const *y) +{ + return !*x && !*y ? true : /* default */ (*x == *y && same (x + 1, y + 1)); +} + +constexpr int +keyToValue (char const *label, entry const *entries) +{ + return !entries->label ? entries->value + : same (entries->label, label) ? entries->value + : /* default */ keyToValue (label, entries + 1); +} + +constexpr entry foo[] = {{"Foo", 0}, {"Bar", 1}, {"FooBar", 2}, {0, -1}}; + +int bar () +{ + int result = keyToValue ("Foo", foo); + return result; +} + +int baz () +{ + constexpr int result = keyToValue ("Foo", foo); + return result; +} + +// Verify that the call to the keyToValue() constexpr function is inlined +// regardless of whether or not it's invoked in a constexpr expression. +// { dg-final { scan-tree-dump-not "keyToValue" "optimized" } } |