问题
Here is the code
//fail_.cpp
template< unsigned char X, class L>
class A {
public:
typedef void (A::*fptr)();
class B {
public: B(typename A< X, L> ::fptr );
};
};
template < unsigned char X, typename L >
A<X,L>::B::B ( fptr ) { }
g++ -c fail_.cpp
gives
fail_.cpp:11: internal compiler error: Segmentation fault
Please submit a full bug report, with preprocessed source if appropriate.
See < file:///usr/share/doc/gcc-4.3/README.Bugs > for instructions.
Looks like a bug to me in g++4.3.5, g++4.4 and higher don't give any such segfault.
What do you guys think? Is there something wrong with the code itself?
回答1:
I see a similar failure with gcc 4.2. As others have said, an internal error means something went badly wrong inside the compiler, which does not imply that it's your code that was bad.
It works fine in g++ 4.6 and clang 3.0.
回答2:
typename should be used as a replacement for class in the template section.
In inner class B, passing the function pointer does not require the keyword typename, because A< X,L> is already known to the compiler at that point.
And maybe giving the typename in front of the type is causing the compiler to malform (may be undefined behavior?).
来源:https://stackoverflow.com/questions/9818751/internal-compiler-error-segmentation-fault-with-g4-3-5