mercredi 28 janvier 2015

gcc/g++ internal error (c++ templated lambda)

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:


main.cpp



#include "B.hpp"

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


B.hpp



#include "A.hpp"

#include <iostream>
#include <functional>

template<typename T>
class B {
int x;

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

A<double> aRet;
return aRet;
};
};


A.hpp



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


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



In file included from main.cpp:1:0:
B.hpp: In instantiation of ‘struct B<int>::<lambda(class A<int>&)>’:
B.hpp:7:7: required from here
B.hpp:11:15: internal compiler error: in tsubst_copy, at cp/pt.c:12569
int xVar = x;
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://ift.tt/1v5WCGL; 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


Aucun commentaire:

Enregistrer un commentaire