0

Could anyone give me a hint why this code produces an internal compiler error? I've tested it on gcc 4.8.1.

#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>

class Dummy {
private:
    int dummy;
public:
    Dummy() { dummy = 0; }
    ~Dummy() { }
    int getDummy() const { return dummy; }
    void setDummy(int d) { dummy = d; }
};

class DummyCollection {
private:
    std::vector<Dummy> table;

public:
    void eachDummy(std::function<bool (const Dummy& d)>& closure) {
        for(const Dummy& d: table) {
            if(! closure(d))
                break;
        }
    }
};

DummyCollection dc;

void iterateDummies(std::function<bool (const Dummy& d)>& closure) {
    dc.eachDummy([&] (const Dummy& d) {
        return closure(d);
    });
}

int main() {
    iterateDummies([&] (const Dummy& d) {
        std::cout << "dummy " << d.getDummy() << std::endl;
        return true;
    });

    return 0;
}

Here's the compiler output:

(2:514)$ g++ test.cpp -o test -std=c++11
test.cpp: In lambda function:
test.cpp:34:2: internal compiler error: in pop_binding, at cp/name-lookup.c:382
  });
  ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.archlinux.org/> for instructions.

Line 34 is the end of the iterateDummies function. It seems that lambda function can't be called from another lambda function, is this true?

2 Answers 2

1

As the output notes, this is not necessarily a defect in your code - the compiler developers have some sort of defect to deal with. You should follow the bug report instructions as linked.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I only wanted to confirm that. I always search for my errors first when dealing with this kind of problems.
1

I've reported this to ArchLinux bugzilla and got this answer, so I'm going to paste it here for other googlers' benefit:

https://bugs.archlinux.org/task/35803

gcc-4.9-20130324 BAD
gcc-4.9-20130331 GOOD

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.