aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C
diff options
context:
space:
mode:
authorBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
committerBen Cheng <bccheng@google.com>2014-03-25 22:37:19 -0700
commit1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch)
treec607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C
parent283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff)
downloadtoolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2
toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C')
-rw-r--r--gcc-4.9/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C27
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C b/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C
new file mode 100644
index 000000000..793b4c3f5
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/g++.dg/cpp0x/constexpr-neg2.C
@@ -0,0 +1,27 @@
+// PR c++/54020
+// { dg-do compile { target c++11 } }
+
+// Preliminaries.
+extern int nonconst_func(int);
+constexpr int identity(int x) { return x; }
+constexpr int zero() { return identity(0); }
+constexpr int one() { return identity(1); }
+
+// Correctly accepted.
+constexpr int three = one() ? 3 : nonconst_func(0);
+
+// Incorrectly accepted. See [dcl.constexpr] #5:
+// For a constexpr function, if no function argument values exist
+// such that the function invocation sub-stitution would produce a
+// constant expression (5.19), the program is ill-formed; no diagnostic
+// required.
+constexpr int bogus() { return zero () ? 3 : nonconst_func(0); } // { dg-error "nonconst_func" }
+
+// Correctly rejected (not sure why).
+constexpr int correct_error() { return nonconst_func(0); } // { dg-error "nonconst_func" }
+
+// Correctly rejected.
+constexpr int z = bogus(); // { dg-error "" }
+
+// This is also correctly rejected.
+constexpr int correct_failure() { return 0 ? 3 : nonconst_func(0); } // { dg-error "nonconst_func" }