From 50e68f9350a355b4a08ba82606789d3c3a163fc3 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 6 Apr 2018 18:09:53 +0000 Subject: [PATCH] PR c++/85214 - ICE with alias, generic lambda, constexpr if. Here, since the condition for the constexpr if depends on the type of 'j', it's still dependent when we are partially instantiating the inner lambda, so we need to defer instantiating the constexpr if. When we instantiated the inner lambda, we tried to substitute into the typename, which failed because we didn't have a declaration of 'i' available. Fixed by teaching extract_locals_r to capture local typedefs such as 'ar'; if we have the typedef handy, we don't need to substitute into its definition. * pt.c (extract_locals_r): Remember local typedefs. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259185 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/pt.c | 5 +++++ gcc/testsuite/g++.dg/cpp1z/constexpr-if20.C | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if20.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e71b4fbe9d8..ba323bf7c20 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2018-04-06 Jason Merrill + + PR c++/85214 - ICE with alias, generic lambda, constexpr if. + * pt.c (extract_locals_r): Remember local typedefs. + 2018-04-06 David Malcolm PR c++/84269 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 450ffaec9be..db3d7e38d85 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11610,6 +11610,11 @@ extract_locals_r (tree *tp, int */*walk_subtrees*/, void *data_) el_data &data = *reinterpret_cast(data_); tree *extra = &data.extra; tsubst_flags_t complain = data.complain; + + if (TYPE_P (*tp) && typedef_variant_p (*tp)) + /* Remember local typedefs (85214). */ + tp = &TYPE_NAME (*tp); + if (TREE_CODE (*tp) == DECL_EXPR) data.internal.add (DECL_EXPR_DECL (*tp)); else if (tree spec = retrieve_local_specialization (*tp)) diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if20.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if20.C new file mode 100644 index 00000000000..24343adb748 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if20.C @@ -0,0 +1,17 @@ +// PR c++/85214 +// { dg-additional-options -std=c++17 } + +struct g { + constexpr operator int() { return true; } +}; +template constexpr bool m = true; +template struct C { typedef double q; }; +void ao() { + [](auto i) { + using ar = typename C::q; + [](auto j) { + using as = typename C::q; + if constexpr (m) {} + }(g()); + }(g()); +} -- 2.11.4.GIT