Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8251579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:17:02+00:00 2026-06-08T00:17:02+00:00

A recent build of GCC 4.8 gives the following code, when in a header

  • 0

A recent build of GCC 4.8 gives the following code, when in a header file:

auto L = [](){};

struct S
{
    decltype(L) m;
};

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
        ^

Why does the compiler consider the type of the lambda to use the anonymous namespace? I made the lambda global, I didn’t use an anonymous namespace anywhere.

UPDATE: The compiles gives the same warning even if I put the lambda in an explicit namespace, like so:

namespace N
{
    auto L = [](){};
}

struct S
{
    decltype(N::L) m;
};

UPDATE 2: In fact, it seems even class scope lambdas have the same problem:

class N
{
    static constexpr auto L = [](){};
};

struct S
{
    decltype(N::L) m;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:17:04+00:00Added an answer on June 8, 2026 at 12:17 am

    GCC’s warning may have been a bit confusing, but its intention is certainly right. The type of the lambda is unnamed, and it is unique in the whole program. On the other side if your class isn’t put in an unnamed namespace (which it, given your description, I suppose is not), your class is the same type in every translation unit that you include it into. Since the same class should have the same members, and not different members in different translation units, this is a violation (and leads to undefined behavior).

    What’s at least as bad is that L is extern, so that you will get “multiple definitions of L” linker errors once you include the header into multiple translation units.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I build gevent, I get an error Traceback (most recent call last): File
Does anyone have any experiences from recent daily build of AnkhSVN? Please let me
The recent update (V 20.x) of Chrome has broken one of my forms with
Following recent hardware problems, I attempted to switch a couple of our websites to
A recent post by John Gruber notes that the following legalese: 3.3.1 — Applications
EDIT following resolution, this has been substantially edited to dump irrelevant detail and explain
Here's the situation, I've got a C++ codebase which is using a recent GCC
root@dicksonxavier-desktop:/home/dicksonxavier/Downloads/MySQL-python-1.2.3# python setup.py build sh: mysql_config: not found Traceback (most recent call last): File
I'm trying to build python 2.5.2 on Solaris 8 using gcc 3.4.2. I can't
On Linux (kernel 2.6.5) our build system calls gcc with -D_REENTRANT . Is this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.