diff mbox

[c++] : Fix PR/63996

Message ID CAEwic4aaeJZ7xFnRabCHanosMzTcf-=EGHPXRv-7x8L2EU8VOw@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Dec. 12, 2014, 10:58 a.m. UTC
Hi,

The loop-expression loops endless in c++14's case for cases the
statement-list isn't constant.

Bug 63996 - Infinite loop in invalid C++14 constexpr fn

ChangeLog

2014-12-12  Kai Tietz  <ktietz@redhat.com>

    PR c++/63996
    * constexpr.c (cxx_eval_loop_expr): Don't loop
    endless on none-constant expression.


2014-12-12  Kai Tietz  <ktietz@redhat.com>

    PR c++/63996
    * g++.dg/cpp1y/pr63996.C: New file.

Tested for x86_64-w64-mingw32.  Ok for apply?

Regards,
Kai

New testcase in g++.dg/cpp1y as pr63996.C

// { dg-do compile { target c++14 } }

constexpr int
foo (int i)
{
  int a[i] = { };
}

constexpr int j = foo (1); // { dg-error "is not a constant expression" }

Comments

Jason Merrill Dec. 12, 2014, 3:49 p.m. UTC | #1
OK.

Jason
Paolo Carlini Dec. 12, 2014, 8:27 p.m. UTC | #2
Hi,

On 12/12/2014 11:58 AM, Kai Tietz wrote:
> New testcase in g++.dg/cpp1y as pr63996.C
>
> // { dg-do compile { target c++14 } }
>
> constexpr int
> foo (int i)
> {
>    int a[i] = { };
> }
>
> constexpr int j = foo (1); // { dg-error "is not a constant expression" }
The testcase fails spuriously because of Jason's VLA reversion commit, 
please adjust it.

Thanks,
Paolo.
Andreas Schwab Dec. 14, 2014, 10:59 a.m. UTC | #3
Kai Tietz <ktietz70@googlemail.com> writes:

> New testcase in g++.dg/cpp1y as pr63996.C
>
> // { dg-do compile { target c++14 } }
>
> constexpr int
> foo (int i)
> {
>   int a[i] = { };
> }
>
> constexpr int j = foo (1); // { dg-error "is not a constant expression" }

FAIL: g++.dg/cpp1y/pr63996.C  -std=c++14 (test for excess errors)
Excess errors:
/usr/local/gcc/gcc-20141214/gcc/testsuite/g++.dg/cpp1y/pr63996.C:6:10: error: ISO C++ forbids variable length array 'a' [-Wvla]

Andreas.
diff mbox

Patch

Index: constexpr.c
===================================================================
--- constexpr.c (Revision 218570)
+++ constexpr.c (Arbeitskopie)
@@ -2841,7 +2870,7 @@  cxx_eval_loop_expr (const constexpr_ctx *ctx, tree
     {
       cxx_eval_statement_list (ctx, body,
                               non_constant_p, overflow_p, jump_target);
-      if (returns (jump_target) || breaks (jump_target))
+      if (returns (jump_target) || breaks (jump_target) || *non_constant_p)
        break;
     }
   if (breaks (jump_target))