http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54060

             Bug #: 54060
           Summary: [C++11] Lambda expression's type should not be in an
                    anonymous namespace
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: zeratul...@hotmail.com


The following code, when in a header file:

auto L = [](){};
struct S
{
    decltype(L) m;
};

Produces the following warning:

test.hpp:3:8: warning: 'S' has a field 'S::m' whose type uses the anonymous
namespace [enabled by default]
 struct S
        ^

This warning suggests that the type of the lambda is in an anonymous namespace. 

A similar warning is given if L is declared at namespace or class scope:

namespace N
{
    auto L = [](){};
}
struct S
{
    decltype(N::L) m;
};


class N
{
    static constexpr auto L = [](){};
};
struct S
{
    decltype(N::L) m;
};


According to section 5.1.2/3 of the Standard,

"The type of the lambda-expression (which is also the type of the closure
object) is a unique, unnamed nonunion class type — called the closure type —
whose properties are described below. This class type is not an aggregate
(8.5.1). The closure type is declared in the smallest block scope, class scope,
or namespace scope that contains the corresponding lambda-expression."

This suggests that the types of the lambdas in the above examples should not be
in an anonymous namespace, because that would not be the smallest scope that
contains the lambda-expression.

Reply via email to