diff options
author | Jason Merrill <jason@redhat.com> | 2016-07-15 14:37:48 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2016-07-15 14:37:48 -0400 |
commit | d1dfa20d80f7e2eab9cf18542e41026439b112d0 (patch) | |
tree | 1c6deabc92b574f1048d6136fb0f89dde5ac96f0 | |
parent | 4db1cb44be3a9121ccbd517824cb280bbf62d833 (diff) | |
download | gcc-d1dfa20d80f7e2eab9cf18542e41026439b112d0.zip gcc-d1dfa20d80f7e2eab9cf18542e41026439b112d0.tar.gz gcc-d1dfa20d80f7e2eab9cf18542e41026439b112d0.tar.bz2 |
PR c++/70824 - initializer_list in template
* init.c (constant_value_1): Don't instantiated DECL_INITIAL of
artificial variables.
From-SVN: r238386
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/init.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/initlist-template1.C | 15 |
3 files changed, 28 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f85a333..81f0a24 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-07-15 Jason Merrill <jason@redhat.com> + + PR c++/70824 + * init.c (constant_value_1): Don't instantiated DECL_INITIAL of + artificial variables. + 2016-07-15 Cesar Philippidis <cesar@codesourcery.com> * parser.c (cp_parser_oacc_declare): Don't scan for diff --git a/gcc/cp/init.c b/gcc/cp/init.c index b4a4388..6047639 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -2073,8 +2073,13 @@ constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p) && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init) == NULL_TREE) init = TREE_VALUE (init); - /* Instantiate a non-dependent initializer. */ - init = instantiate_non_dependent_or_null (init); + /* Instantiate a non-dependent initializer for user variables. We + mustn't do this for the temporary for an array compound literal; + trying to instatiate the initializer will keep creating new + temporaries until we crash. Probably it's not useful to do it for + other artificial variables, either. */ + if (!DECL_ARTIFICIAL (decl)) + init = instantiate_non_dependent_or_null (init); if (!init || !TREE_TYPE (init) || !TREE_CONSTANT (init) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-template1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-template1.C new file mode 100644 index 0000000..a24e205 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-template1.C @@ -0,0 +1,15 @@ +// PR c++/70824 +// { dg-do compile { target c++11 } } + +#include <initializer_list> + +constexpr +int +max(std::initializer_list<int> __l) +{ return *__l.begin(); } + +template <class Src> +void +a() { + const int v = max({1}); +} |