I stumbled over a possible bug in g++ (at least it told me to file a bug report). I'm not exactly sure if the code I tried to compile is correct. ~/bug > g++ -v -save-temps -I/usr/local/include gpp_bug.cpp Using built-in specs. Configured with: FreeBSD/i386 system compiler Thread model: posix gcc version 3.4.2 [FreeBSD] 20040728 /usr/libexec/cc1plus -E -quiet -v -I/usr/local/include -D_LONGLONG gpp_bug.cpp -o gpp_bug.ii ignoring duplicate directory "/usr/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/include/c++/3.4 /usr/include/c++/3.4/backward /usr/include End of search list. /usr/libexec/cc1plus -fpreprocessed gpp_bug.ii -quiet -dumpbase gpp_bug.cpp -auxbase gpp_bug -version -o gpp_bug.s GNU C++ version 3.4.2 [FreeBSD] 20040728 (i386-fbsdproj-freebsd) compiled by GNU C version 3.4.2 [FreeBSD] 20040728. GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 g++: Internal error: Illegal instruction (program cc1plus) Please submit a full bug report. See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Created attachment 10092 [details] preprocessed source file
This is a true C++ front-end problem, in that the seg fault is due to a stack overflow in the C++ front-end. I think this is a regression but I have not tried to reduce it yet.
With the source here, I was able to find a different issue which I will be posting soon.
Note the backtrace for the orginal issue is: #28 0x000000000040bb94 in convert_like_real (convs=Variable "convs" is not available. ) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4379 #29 0x000000000040c241 in build_over_call (cand=0x15009b8, flags=1067) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4804 #30 0x000000000040aacd in build_new_method_call (instance=0x2aaaadbb4a40, fns=Variable "fns" is not available. ) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:5441 #31 0x000000000040b5fa in convert_like_real (convs=0x15006e8, expr=0x2aaaabf002c0, fn=0x2aaaabacd100, argnum=0, inner=-1, issue_conversion_warnings=0 '\0', c_cast_p=0 '\0') at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4293 #32 0x000000000040b71e in convert_like_real (convs=0x1500710, expr=0x2aaaabf002c0, fn=0x2aaaabacd100, argnum=0, inner=0, issue_conversion_warnings=1 '\001', c_cast_p=0 '\0') at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4304 #33 0x000000000040c241 in build_over_call (cand=0x1500738, flags=3) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:4804 #34 0x000000000040aacd in build_new_method_call (instance=0x2aaaadbb49c0, fns=Variable "fns" is not available. ) at /home/pinskia/src/newtest/trunk/gcc/cp/call.c:5441 #35 0x00000000004b5c9f in ocp_convert (type=0x2aaaabab5420, expr=0x2aaaabf002c0, convtype=Variable "convtype" is not available. ) at /home/pinskia/src/newtest/trunk/gcc/cp/cvt.c:764 #
PR 24606 is the other issue I found.
Reduced testcase: struct string; struct _Deque_iterator { string &operator*() const; }; template<typename _Function> void for_each(_Function __f) { _Deque_iterator __first1; __f(*__first1); } struct locale { locale(const locale& __other) throw(); }; template<typename SequenceT> void trim(string& Input, const locale& Loc=locale()); int main() { for_each(trim<string>); } ---- This one also ICEs with ICC. I will let someone else decide if this is valid or invalid code and then confirm it.
Here's a sightly simpler testcase. If I remove the copy-ctor from A, I get the failure from PR24606. ========================================= template<typename F> void foo(F f) { f(); } struct A { A(); A(const A&); }; template<int> void bar(A = A()); void baz() { foo(bar<0>); } ========================================= Btw, removing the template from "bar" makes the code compile. So it seems like the code is valid after all.
Since Nathan's patch for PR32839, we get the following error message for the testcase in comment #7 (and similar messages for the original testcase, the testcase in comment #6, and PR 24606): bug.cc: In function 'void foo(F) [with F = void (*)(A)]': bug.cc:16: instantiated from here bug.cc:3: error: too few arguments to function I get the same error message if I make bar a non-template function. In contrast to my last sentence of comment #7, I now think the compiler does the right thing here. Nathan, do you think so, too? If yes, we can close this bug as fixed.
*** Bug 24606 has been marked as a duplicate of this bug. ***
Nathan confirmed in private mail that the compiler now does the right thing. So closing as fixed.
*** Bug 35596 has been marked as a duplicate of this bug. ***