c++: Remove superflous assert [PR104403]
authorJakub Jelinek <jakub@redhat.com>
Tue, 8 Feb 2022 19:15:42 +0000 (20:15 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 8 Feb 2022 19:15:42 +0000 (20:15 +0100)
I've added the assert because start_decl diagnoses such vars for C++20 and
earlier:
  if (current_function_decl && VAR_P (decl)
      && DECL_DECLARED_CONSTEXPR_P (current_function_decl)
      && cxx_dialect < cxx23)
but as can be seen, we cam trigger the assert in older standards e.g. during
non-manifestly constant evaluation.  Rather than refining the assert that
DECL_EXPRs for such vars don't appear for C++20 and older if they are inside
of functions declared constexpr this patch just removes the assert, the
code rejects encountering those vars in constant expressions anyway.

2022-02-08  Jakub Jelinek  <jakub@redhat.com>

PR c++/104403
* constexpr.cc (cxx_eval_constant_expression): Don't assert DECL_EXPRs
of TREE_STATIC vars may only appear in -std=c++23.

* g++.dg/cpp0x/lambda/lambda-104403.C: New test.

gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C [new file with mode: 0644]

index fd05117..9b8e0ec 100644 (file)
@@ -6652,7 +6652,6 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
            /* Allow __FUNCTION__ etc.  */
            && !DECL_ARTIFICIAL (r))
          {
-           gcc_assert (cxx_dialect >= cxx23);
            if (!ctx->quiet)
              {
                if (CP_DECL_THREAD_LOCAL_P (r))
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-104403.C
new file mode 100644 (file)
index 0000000..f231d3e
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/104403
+// { dg-do compile { target c++11 } }
+
+int
+main ()
+{
+  []{ switch (0) { case 0: static int value; return &value; } };
+}