public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "zeratul976 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/54060] New: [C++11] Lambda expression's type should not be in an anonymous namespace
Date: Sat, 21 Jul 2012 06:55:00 -0000	[thread overview]
Message-ID: <bug-54060-4@http.gcc.gnu.org/bugzilla/> (raw)

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: unassigned@gcc.gnu.org
        ReportedBy: zeratul976@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	other threads:[~2012-07-21  6:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-21  6:55 zeratul976 at hotmail dot com [this message]
2012-07-31 19:15 ` [Bug c++/54060] G++ warning mixes up anonymous types and anonymous namespaces jason at gcc dot gnu.org
2012-07-31 20:22 ` zeratul976 at hotmail dot com
2012-07-31 20:42 ` redi at gcc dot gnu.org
2013-06-15 18:16 ` paolo.carlini at oracle dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-54060-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).