aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-08-28 02:03:48 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2019-08-28 02:03:48 +0000
commit14da3939da3adcef84816573caa9d93c7367507e (patch)
tree1bc500d3505ce6feb8743a102df9a66cbb3bf3d4 /gcc/testsuite
parent4719ac2f2d1d770a840316d02e68fdff8e223129 (diff)
downloadgcc-14da3939da3adcef84816573caa9d93c7367507e.zip
gcc-14da3939da3adcef84816573caa9d93c7367507e.tar.gz
gcc-14da3939da3adcef84816573caa9d93c7367507e.tar.bz2
PR c++/91428 - warn about std::is_constant_evaluated in if constexpr.
* cp-tree.h (decl_in_std_namespace_p): Declare. * semantics.c (is_std_constant_evaluated_p): New. (finish_if_stmt_cond): Warn about "std::is_constant_evaluated ()" in an if-constexpr. * typeck.c (decl_in_std_namespace_p): No longer static. * g++.dg/cpp2a/is-constant-evaluated9.C: New test. From-SVN: r274981
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated9.C49
2 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cd6fb7f..ade1a69 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-08-27 Marek Polacek <polacek@redhat.com>
+
+ PR c++/91428 - warn about std::is_constant_evaluated in if constexpr.
+ * g++.dg/cpp2a/is-constant-evaluated9.C: New test.
+
2019-08-27 Martin Sebor <msebor@redhat.com>
PR tree-optimization/91567
diff --git a/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated9.C b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated9.C
new file mode 100644
index 0000000..3783369
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/is-constant-evaluated9.C
@@ -0,0 +1,49 @@
+// PR c++/91428 - warn about std::is_constant_evaluated in if constexpr.
+// { dg-do compile { target c++2a } }
+// { dg-options "-Wtautological-compare" }
+
+namespace std {
+ constexpr inline bool
+ is_constant_evaluated () noexcept
+ {
+ return __builtin_is_constant_evaluated ();
+ }
+}
+
+constexpr int
+foo(int i)
+{
+ if constexpr (std::is_constant_evaluated ()) // { dg-warning ".std::is_constant_evaluated. always evaluates to true in .if constexpr." }
+ return 42;
+ else
+ return i;
+}
+
+constexpr int
+foo2(int i)
+{
+ if constexpr (__builtin_is_constant_evaluated ()) // { dg-warning ".std::is_constant_evaluated. always evaluates to true in .if constexpr." }
+ return 42;
+ else
+ return i;
+}
+
+constexpr int
+foo3(int i)
+{
+ // I is not a constant expression but we short-circuit it.
+ if constexpr (__builtin_is_constant_evaluated () || i)
+ return 42;
+ else
+ return i;
+}
+
+constexpr int
+foo4(int i)
+{
+ const int j = 0;
+ if constexpr (j && __builtin_is_constant_evaluated ())
+ return 42;
+ else
+ return i;
+}