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

  • Home
  • SEARCH
  • 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 8426061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:26:43+00:00 2026-06-10T04:26:43+00:00

I created a macro that conveniently builds lambda functions using which I can iterate

  • 0

I created a macro that conveniently builds lambda functions using which I can iterate through tensor objects in a library that I wrote. However, nesting these macros seemed to cause GCC to undergo an internal segmentation fault. Upon expanding the compiler’s preprocessor output and going through some trial and error, I discovered that cause seems to be the use of decltype in the parameter list of a nested lambda function declared in the method of a class or struct. Below follows a minimal example using the standard library.

#include <iostream>
#include <type_traits>

template <class Iterator, class Func>
void for_each(const Iterator first, const Iterator last, Func func)
{
        for (Iterator it = first; it != last; ++it) {
                func(*it);
        }
}

template <class T>
class helper
{
        typedef typename T::size_type type;
};

template <class T>
class helper<T&>
{
        typedef typename T::size_type type;
};

template <class T>
class helper<T*>
{
        typedef typename T::size_type type;
};      

struct bar
{
        struct foo
        {
                typedef int size_type;
        } foo_;

        void test()
        {
                int arr[] = { 1, 2, 3 };
                for_each(arr, arr + 3, [&](int i) {
                        /*
                        ** XXX: The "typename ... type" segfaults g++!
                        */
                        for_each(arr, arr + 3, [&](typename helper<decltype(foo_)>::type j) {

                        });
                });
        }
};

int main()
{
        return 0;
}

Compiler Output:

$ g++ -Wall -std=c++0x nested_lambda.cpp
nested_lambda.cpp: In lambda function:
nested_lambda.cpp:42:56: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
Preprocessed source stored into /tmp/ccqYohFA.out file, please attach this to your bugreport.

I initially opted to use decltype because an object is passed to a macro, and I need to extract the object’s type. From the object’s type, (T, T&, or T*), I’d use a traits class to pull T::size_type. size_type would then be the type of the lambda function parameters.

How can I circumvent this issue without having to use a typedef to declare the type of the lambda function parameter in advance? If you can think of some other solution that could easily be implemented in a macro (i.e. copied and pasted repeatedly in the parameter list of a lambda function), that would work too.

  • 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-10T04:26:45+00:00Added an answer on June 10, 2026 at 4:26 am

    This bug is currently being addressed, and I think that it should be fixed soon.

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

Sidebar

Related Questions

I have created a macro for excel which will pop up form that contains
I have already created a Macro using a 3rd party application that does what
Using primarily the macro recorder, I created a VBA macro that sets up a
I've created latex macro to typeset guitar chords diagrams(using picture environment). Now I want
I'm having trouble obtaining data with a macro I've created using XSLT. I have
Trying to create a macro which can be used for print debug messages when
I created a macro that doesn't allow values in both the B and C
I'm a relative VBA novice, and designing a fairly complex macro that can run
We've created a flow chart using Visio that has multiple layers. (The background is
I have created a macro enabled Excel Spreadsheet that will programmatically load a image

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.