1

i was just making a few changes to my program, when all of a sudden g++ complained with an internal compiler error.

Clang however compiles it without any problems and also does not give any warnings, that would indicate anything weird.

I distilled the problem down to this:

#include <functional>

template<typename T>
class A{
    T someVar;
};

template<typename T>
class B {
        int x;

        std::function<A<double>(A<int>&)> someLambda = [&](A<int>& aInt){
            int xVar = x;
            A<double> aRet;
            return aRet;
        };
};

int main(int argc, char** argv){
    B<int> a;
    return 0;
}

I tried both GCC 4.9.2 and 4.8.4, with both failing (internal compiler error).

Flags I used:

g++ -std=c++11 -O0 -g -Wall main.cpp -o gccBin

clang++ -std=c++11 -O0 -g -Wall main.cpp -o clangBin

main.cpp: In instantiation of 'struct B<int>::<lambda(class A<int>&)>':
main.cpp:10:7:   required from here
main.cpp:14:24: internal compiler error: in tsubst_copy, at cp/pt.c:12569
             int xVar = x;
                        ^
libbacktrace could not find executable to open
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Clang++(3.5.1) compiles it without a problem, as I mentioned. I also tried multiple machines, everywhere the same.

Is there some kind of error I overlooked? I searched a bit on the internet and the only similar problems i could find should have been fixed by now (as the bugtracker states).

Could maybe someone try and run this code on their machine or give other advice?

Thank you,

Lazarus

7
  • 3
    If GCC is having an internal compiler error, that is a compiler bug, period. This is not your mistake. However, there might be a workaround. Commented Jan 28, 2015 at 21:04
  • It is so wierd that the error goes away if we remove the unused xVar O.o Something to do with the size of the lambda or callstack or something? Commented Jan 28, 2015 at 21:16
  • check with the latest version of the compiler, if the problem still exists, submit... Commented Jan 28, 2015 at 21:25
  • Thanks for clarification for the editing Mooing Duck. What would be your workaround? Commented Jan 28, 2015 at 21:50
  • 1
    A minimal working example looks like this: #include <functional> template<typename T> class A { int x; std::function<void()> someLambda = [&](){x;}; }; int main(){ A<int> a; } Commented Jan 28, 2015 at 22:14

1 Answer 1

3

It's a compiler bug. Just go ahead and file a bug report to the GCC dudes!

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

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.