From 8859913ea3cbefdcf1aaec654744a358420d8138 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 4 Apr 2018 15:10:38 -0400 Subject: [PATCH] PR c++/85200 - ICE with constexpr if in generic lambda. * tree.c (cp_walk_subtrees): Walk into DECL_EXPR in templates. From-SVN: r259099 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/tree.c | 8 +++++--- gcc/testsuite/g++.dg/cpp1z/constexpr-if18.C | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if18.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9b754199e69..12d0c10efd5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2018-04-04 Jason Merrill + PR c++/85200 - ICE with constexpr if in generic lambda. + * tree.c (cp_walk_subtrees): Walk into DECL_EXPR in templates. + PR c++/84221 - bogus -Wunused with attribute and template. * decl2.c (is_late_template_attribute): Handle unused and used normally on non-TYPE_DECL. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 7ddc2cb5e2d..d0835cfaa29 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -4894,10 +4894,12 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, /* User variables should be mentioned in BIND_EXPR_VARS and their initializers and sizes walked when walking the containing BIND_EXPR. Compiler temporaries are - handled here. */ + handled here. And also normal variables in templates, + since do_poplevel doesn't build a BIND_EXPR then. */ if (VAR_P (TREE_OPERAND (*tp, 0)) - && DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0)) - && !TREE_STATIC (TREE_OPERAND (*tp, 0))) + && (processing_template_decl + || (DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0)) + && !TREE_STATIC (TREE_OPERAND (*tp, 0))))) { tree decl = TREE_OPERAND (*tp, 0); WALK_SUBTREE (DECL_INITIAL (decl)); diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if18.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if18.C new file mode 100644 index 00000000000..03ad620e8d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if18.C @@ -0,0 +1,15 @@ +// PR c++/85200 +// { dg-additional-options -std=c++17 } + +template +void f(){ + [](auto v, auto b){ + if constexpr (sizeof(v) == sizeof(int)) { + auto x = b; + } + }(0, 1); +} + +int main(){ + f(); +} -- 2.30.2