PR c++/93324 - ICE with -Wall on constexpr if.
authorMarek Polacek <polacek@redhat.com>
Wed, 22 Jan 2020 16:44:13 +0000 (11:44 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 22 Jan 2020 16:44:13 +0000 (11:44 -0500)
This is a crash with constexpr if, when trying to see if the call in
the if-statement is std::is_constant_evaluated.

cp_get_callee_fndecl_nofold can return NULL_TREE and fndecl_built_in_p
doesn't expect to get a null tree, so check FNDECL first.

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C [new file with mode: 0644]

index 3d5823832279a17e75b1e324fff65d07fdb5e65f..d9946997ba093e8d12c46b126e5a33cf990b9b84 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/93324 - ICE with -Wall on constexpr if.
+       * semantics.c (is_std_constant_evaluated_p): Check fndecl.
+
 2020-01-22  Patrick Palka  <ppalka@redhat.com>
 
        * constraint.cc (get_mapped_args): Avoid using auto_vec
index 3669b247e3468d142b9acd2deb31a474ae06550b..3b88f1520bc88e7b879b5acaa98b1f8276882531 100644 (file)
@@ -734,6 +734,9 @@ is_std_constant_evaluated_p (tree fn)
     return false;
 
   tree fndecl = cp_get_callee_fndecl_nofold (fn);
+  if (fndecl == NULL_TREE)
+    return false;
+
   if (fndecl_built_in_p (fndecl, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
                         BUILT_IN_FRONTEND))
     return true;
index d22747b1dfed2d65eee7d30987f09b0160a34463..70d7e8869e1816dc811952856bedb61a5b72c365 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/93324 - ICE with -Wall on constexpr if.
+       * g++.dg/cpp1z/constexpr-if33.C: New test.
+
 2020-01-22  Richard Sandiford  <richard.sandiford@arm.com>
 
        * gcc.target/aarch64/sve/acle/general/stack_vars_1.c: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if33.C
new file mode 100644 (file)
index 0000000..e5ef659
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/93324 - ICE with -Wall on constexpr if.
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wall" }
+
+struct {
+  template <int>
+  static constexpr bool a() { return 0; }
+} e;
+
+template <typename>
+void d()
+{
+  auto c(e);
+  using b = decltype(c);
+  if constexpr (b::a<2>());
+}