diff options
author | Jason Merrill <jason@redhat.com> | 2016-03-23 14:23:04 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2016-03-23 14:23:04 -0400 |
commit | 96a4ef9d6a40af1df81b3a2ec1574c31bdba2213 (patch) | |
tree | 84e28f8b34041b9790f900f67ee25377a1a2a6e1 | |
parent | fbdb6bafe2be0f4e12b85dcb92641bb55078bf72 (diff) | |
download | gcc-96a4ef9d6a40af1df81b3a2ec1574c31bdba2213.zip gcc-96a4ef9d6a40af1df81b3a2ec1574c31bdba2213.tar.gz gcc-96a4ef9d6a40af1df81b3a2ec1574c31bdba2213.tar.bz2 |
re PR c++/70344 (ICE on invalid code at -O1 and above on x86_64-linux-gnu in record_reference, at cgraphbuild.c:64)
PR c++/70344
* constexpr.c (cxx_eval_call_expression): Catch invalid recursion.
From-SVN: r234434
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C | 17 |
3 files changed, 37 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d361689..01fc2bd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-03-23 Jason Merrill <jason@redhat.com> + + PR c++/70344 + * constexpr.c (cxx_eval_call_expression): Catch invalid recursion. + 2016-03-23 Marek Polacek <polacek@redhat.com> PR c++/69884 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 7b13633..d71e488 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1239,6 +1239,21 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, return t; } + if (fun == current_function_decl) + { + /* A call to the current function, i.e. + constexpr int f (int i) { + constexpr int j = f(i-1); + return j; + } + This would be OK without the constexpr on the declaration of j. */ + if (!ctx->quiet) + error_at (loc, "%qD called in a constant expression before its " + "definition is complete", fun); + *non_constant_p = true; + return t; + } + constexpr_ctx new_ctx = *ctx; if (DECL_CONSTRUCTOR_P (fun) && !ctx->object && TREE_CODE (t) == AGGR_INIT_EXPR) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C new file mode 100644 index 0000000..978b998 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C @@ -0,0 +1,17 @@ +// PR c++/70344 +// { dg-do compile { target c++11 } } + +struct Z +{ + Z () = default; + Z (Z const &) = default; + constexpr Z (Z &&) {} +}; + +constexpr int +fn (Z v) +{ + return fn (v); +} + +auto t = fn (Z ()); |