From: Jason Merrill Date: Sat, 16 Jun 2018 06:35:53 +0000 (-0400) Subject: PR c++/86147 - wrong capture for template argument. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=94aedc1c0e27aca2b473c35172b564520a7a63ee;p=gcc.git PR c++/86147 - wrong capture for template argument. * expr.c (mark_use): Look through NOP_EXPR. From-SVN: r261676 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 56fe205fdbc..2e341f10527 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2018-06-15 Jason Merrill + PR c++/86147 - wrong capture for template argument. + * expr.c (mark_use): Look through NOP_EXPR. + * name-lookup.c (do_pushtag): Don't look through complete types, but don't add to them either. Get context from current_binding_level. * pt.c (tsubst_default_argument): Use push_to/pop_from_top_level. diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c index 9780b75d1cd..133a01b8a51 100644 --- a/gcc/cp/expr.c +++ b/gcc/cp/expr.c @@ -186,12 +186,15 @@ mark_use (tree expr, bool rvalue_p, bool read_p, expr = convert_from_reference (r); } break; - default: + + CASE_CONVERT: + case VIEW_CONVERT_EXPR: if (location_wrapper_p (expr)) - { - loc = EXPR_LOCATION (expr); - recurse_op[0] = true; - } + loc = EXPR_LOCATION (expr); + recurse_op[0] = true; + break; + + default: break; } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const9.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const9.C new file mode 100644 index 00000000000..0724ae15d88 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const9.C @@ -0,0 +1,17 @@ +// PR c++/86147 +// { dg-do compile { target c++11 } } + +template struct X { }; + +struct A { static constexpr int value = 0; }; + +template +void foo() { + constexpr int N = C::value; + auto f = [&]{ X a; }; +} + +int main() { + foo(); + return 0; +}