summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>2016-03-15 03:05:17 +0000
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>2016-03-15 03:05:17 +0000
commit7bad2faf72b5290c1f6b545952f529222759e006 (patch)
treeb05cf8fc1e8c4f2b0f08902a4ac834acc5e6c6a5
parent6f89583213e56858ea8709d17b8d4fcc66931a76 (diff)
downloadgcc-7bad2faf72b5290c1f6b545952f529222759e006.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234208 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-inline-1.C29
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-inline.C40
3 files changed, 75 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d9015bb2ed2..e9b0a9aeed0 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 00000000000..fed69904912
--- /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 00000000000..d04257c8c33
--- /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" } }