Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk?
-- >8 -- For decltype((x)) within a lambda where x is not captured, we dubiously require that the lambda has a capture default, unlike for decltype(x). This patch fixes this inconsistency; I couldn't find a justification for it in the standard. PR c++/83167 gcc/cp/ChangeLog: * semantics.cc (finish_decltype_type): If capture_decltype returns NULL_TREE, fall back to the ordinary code path. (capture_decltype): Return NULL_TREE if the lambda has no capture-default. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-decltype4.C: New test. --- gcc/cp/semantics.cc | 6 +++--- .../g++.dg/cpp0x/lambda/lambda-decltype4.C | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 8090c71809f..6fdd6c45972 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11732,7 +11732,8 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, /* If the expression is just "this", we want the cv-unqualified pointer for the "this" type. */ type = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); - else + + if (!type) { /* Otherwise, where T is the type of e, if e is an lvalue, decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */ @@ -12639,8 +12640,7 @@ capture_decltype (tree decl) switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam)) { case CPLD_NONE: - error ("%qD is not captured", decl); - return error_mark_node; + return NULL_TREE; case CPLD_COPY: type = TREE_TYPE (decl); diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C new file mode 100644 index 00000000000..0062d7b8672 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-decltype4.C @@ -0,0 +1,15 @@ +// PR c++/83167 +// { dg-do compile { target c++11 } } + +int main() { + int x; + const int y = 42; + + [] { + using ty1 = decltype((x)); + using ty1 = int&; + + using ty2 = decltype((y)); + using ty2 = const int&; + }; +} -- 2.43.0.rc1