public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54060] New: [C++11] Lambda expression's type should not be in an anonymous namespace
@ 2012-07-21  6:55 zeratul976 at hotmail dot com
  2012-07-31 19:15 ` [Bug c++/54060] G++ warning mixes up anonymous types and anonymous namespaces jason at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zeratul976 at hotmail dot com @ 2012-07-21  6:55 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/54060] G++ warning mixes up anonymous types and anonymous namespaces
  2012-07-21  6:55 [Bug c++/54060] New: [C++11] Lambda expression's type should not be in an anonymous namespace zeratul976 at hotmail dot com
@ 2012-07-31 19:15 ` jason at gcc dot gnu.org
  2012-07-31 20:22 ` zeratul976 at hotmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2012-07-31 19:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2012-07-31
                 CC|                            |jason at gcc dot gnu.org
     Ever Confirmed|0                           |1
            Summary|[C++11] Lambda expression's |G++ warning mixes up
                   |type should not be in an    |anonymous types and
                   |anonymous namespace         |anonymous namespaces

--- Comment #1 from Jason Merrill <jason at gcc dot gnu.org> 2012-07-31 19:15:21 UTC ---
The lambda isn't really in the anonymous namespace, the warning message is
misleading.  This also happens for non-lambda anonymous types, such as

typedef struct { } *A;

struct B
{
  A a;
};


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/54060] G++ warning mixes up anonymous types and anonymous namespaces
  2012-07-21  6:55 [Bug c++/54060] New: [C++11] Lambda expression's type should not be in an anonymous namespace zeratul976 at hotmail dot com
  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
  3 siblings, 0 replies; 5+ messages in thread
From: zeratul976 at hotmail dot com @ 2012-07-31 20:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Nathan Ridge <zeratul976 at hotmail dot com> 2012-07-31 20:21:51 UTC ---
What is the purpose of warning about the use of an anonymous type in this
context?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/54060] G++ warning mixes up anonymous types and anonymous namespaces
  2012-07-21  6:55 [Bug c++/54060] New: [C++11] Lambda expression's type should not be in an anonymous namespace zeratul976 at hotmail dot com
  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
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-07-31 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-07-31 20:41:51 UTC ---
Every file that includes the code gets a different type, so S (in comment 0)
and B (in comment 1) violate the ODR if defined in more than one translation
unit. That's why the warning is given when the code occurs in a header.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/54060] G++ warning mixes up anonymous types and anonymous namespaces
  2012-07-21  6:55 [Bug c++/54060] New: [C++11] Lambda expression's type should not be in an anonymous namespace zeratul976 at hotmail dot com
                   ` (2 preceding siblings ...)
  2012-07-31 20:42 ` redi at gcc dot gnu.org
@ 2013-06-15 18:16 ` paolo.carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-15 18:16 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Same issue, right? And it seems easy to fix, we have only to reword a bit the
message.

*** This bug has been marked as a duplicate of bug 53184 ***


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-15 18:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-21  6:55 [Bug c++/54060] New: [C++11] Lambda expression's type should not be in an anonymous namespace zeratul976 at hotmail dot com
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

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).