public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/66153] New: Internal compiler error in nested template function @ 2015-05-15 0:21 paboyle at ph dot ed.ac.uk 2015-05-15 11:42 ` [Bug c++/66153] " paboyle at ph dot ed.ac.uk ` (6 more replies) 0 siblings, 7 replies; 8+ messages in thread From: paboyle at ph dot ed.ac.uk @ 2015-05-15 0:21 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 Bug ID: 66153 Summary: Internal compiler error in nested template function Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: paboyle at ph dot ed.ac.uk Target Milestone: --- Created attachment 35543 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35543&action=edit Preprocessed source Peters-MacBook-Pro:gcc5_debug pab$ g++-5 -std=c++11 broken.cc -o broken ' Internal compiler error: Error reporting routines re-entered. broken.cc: In substitution of 'template<int N, class obj> Container<decltype (function<N>(arg.data[0]))> function(const Container<obj>&) [with int N = 1; obj = <missing>]': broken.cc:43:101: recursively required by substitution of 'template<int N, class obj> Container<decltype (function<N>(arg.data[0]))> function(const Container<obj>&) [with int N = 1; obj = <missing>]' broken.cc:43:101: required by substitution of 'template<int N, class obj> Container<decltype (function<N>(arg.data[0]))> function(const Container<obj>&) [with int N = 1; obj = <missing>]' broken.cc:45:33: Abort trap: 6 template<int N,class obj> auto function(const Container<obj> & arg)-> Container<decltype(function<N>(arg.data[0]))> ^ g++-5: internal compiler error: Abort trap: 6 (program cc1plus) Please submit a full bug report, with preprocessed source if appropriate. See <https://github.com/Homebrew/homebrew-versions/issues> for instructions. ============== #include <vector> #include <complex> #include <type_traits> #include <iostream> typedef std::complex<double> ComplexD; template <class T> class TypeMapper { public: enum { NestLevel = T::NestLevel }; }; template<> class TypeMapper<ComplexD> { public: enum { NestLevel = 0 }; }; template<class obj> class Container { public: std::vector<obj> data; Container(int size) : data (size){}; }; template<class obj> class Recursive { public: enum { NestLevel = TypeMapper<obj>::NestLevel + 1}; obj internal; }; template<int N,class obj,typename std::enable_if<N==obj::NestLevel >::type * = nullptr > auto function(const obj &arg)-> obj { std::cout<<"Leaf "<<obj::NestLevel<<std::endl; return arg; } template<int N,class obj,typename std::enable_if<N!=obj::NestLevel >::type * = nullptr > auto function(const obj &arg)-> obj { std::cout<<"Node "<<obj::NestLevel<<std::endl; obj ret; ret.internal=function<N>(arg.internal); return ret; } template<int N,class obj> auto function(const Container<obj> & arg)-> Container<decltype(function<N>(arg.data[0]))> { Container<decltype(function<N>(arg.data[0]))> ret(arg.data.size()); for(int ss=0;ss<arg.data.size();ss++){ ret.data[ss] = function<N>(arg.data[ss]); } return ret; } int main(int argc,char **argv) { Container<Recursive<Recursive<ComplexD> > > array(10); Container<Recursive<Recursive<ComplexD> > > ret(10); ret = function<1>(array); } ============== For reference, works on Intel 15, Clang++ multiple versions. Peters-MacBook-Pro:gcc5_debug pab$ icpc -std=c++11 broken.cc -o broken Peters-MacBook-Pro:gcc5_debug pab$ clang++ -std=c++11 broken.cc -o broken Peters-MacBook-Pro:gcc5_debug pab$ clang++ --version Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.1.0 Thread model: posix Peters-MacBook-Pro:gcc5_debug pab$ icpc --version icpc (ICC) 15.0.3 20150408 Copyright (C) 1985-2015 Intel Corporation. All rights reserved. Output with both icpc and clang++ is: Peters-MacBook-Pro:gcc5_debug pab$ ./broken Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 Node 2 Leaf 1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/66153] Internal compiler error in nested template function 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk @ 2015-05-15 11:42 ` paboyle at ph dot ed.ac.uk 2015-05-16 4:41 ` paboyle at ph dot ed.ac.uk ` (5 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: paboyle at ph dot ed.ac.uk @ 2015-05-15 11:42 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 --- Comment #1 from Peter Boyle <paboyle at ph dot ed.ac.uk> --- Created attachment 35547 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35547&action=edit unprocessed source code. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/66153] Internal compiler error in nested template function 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk 2015-05-15 11:42 ` [Bug c++/66153] " paboyle at ph dot ed.ac.uk @ 2015-05-16 4:41 ` paboyle at ph dot ed.ac.uk 2015-05-23 12:47 ` paboyle at ph dot ed.ac.uk ` (4 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: paboyle at ph dot ed.ac.uk @ 2015-05-16 4:41 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 --- Comment #2 from Peter Boyle <paboyle at ph dot ed.ac.uk> --- p.s. in case anyone is wondering this recursive construct is a simplification of a construct I'm using in an expression template framework, so this is not simply a convoluted test case. Rather, I distilled the fail down to a small case from a much larger code. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/66153] Internal compiler error in nested template function 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk 2015-05-15 11:42 ` [Bug c++/66153] " paboyle at ph dot ed.ac.uk 2015-05-16 4:41 ` paboyle at ph dot ed.ac.uk @ 2015-05-23 12:47 ` paboyle at ph dot ed.ac.uk 2021-12-21 21:11 ` pinskia at gcc dot gnu.org ` (3 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: paboyle at ph dot ed.ac.uk @ 2015-05-23 12:47 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 Peter Boyle <paboyle at ph dot ed.ac.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Version|5.1.0 |6.0 --- Comment #4 from Peter Boyle <paboyle at ph dot ed.ac.uk> --- Also fails in HEAD prog.cc:53:14: warning: unused parameter 'argc' [-Wunused-parameter] int main(int argc,char **argv) ^ prog.cc:53:26: warning: unused parameter 'argv' [-Wunused-parameter] int main(int argc,char **argv) ^ ' Internal compiler error: Error reporting routines re-entered. 0x5ccf96 push_tinst_level_loc(tree_node*, unsigned int) /home/heads/gcc/gcc-source/gcc/cp/pt.c:8464 0x5e8409 push_tinst_level(tree_node*) /home/heads/gcc/gcc-source/gcc/cp/pt.c:8448 0x5e8409 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node* const*, unsigned int, tree_node*, unification_kind_t, int, bool, bool) /home/heads/gcc/gcc-source/gcc/cp/pt.c:16238 0x5a5be9 add_template_candidate_real /home/heads/gcc/gcc-source/gcc/cp/call.c:3057 0x5a626c add_template_candidate /home/heads/gcc/gcc-source/gcc/cp/call.c:3154 0x5a626c add_candidates /home/heads/gcc/gcc-source/gcc/cp/call.c:5281 0x5a8843 perform_overload_resolution /home/heads/gcc/gcc-source/gcc/cp/call.c:3999 0x5a9d0a build_new_function_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, int) /home/heads/gcc/gcc-source/gcc/cp/call.c:4076 0x67114a finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int) /home/heads/gcc/gcc-source/gcc/cp/semantics.c:2410 0x5d478d tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) /home/heads/gcc/gcc-source/gcc/cp/pt.c:15201 0x5d5308 tsubst(tree_node*, tree_node*, int, tree_node*) /home/heads/gcc/gcc-source/gcc/cp/pt.c:12512 0x60dd50 dump_template_bindings /home/heads/gcc/gcc-source/gcc/cp/error.c:369 0x60dd50 dump_substitution /home/heads/gcc/gcc-source/gcc/cp/error.c:1448 0x60f866 decl_to_string /home/heads/gcc/gcc-source/gcc/cp/error.c:2910 0x60f866 cp_printer /home/heads/gcc/gcc-source/gcc/cp/error.c:3491 0xfd6a10 pp_format(pretty_printer*, text_info*) /home/heads/gcc/gcc-source/gcc/pretty-print.c:613 0xfd7780 pp_format_verbatim(pretty_printer*, text_info*) /home/heads/gcc/gcc-source/gcc/pretty-print.c:672 0xfd7854 pp_verbatim(pretty_printer*, char const*, ...) /home/heads/gcc/gcc-source/gcc/pretty-print.c:873 0x609eda print_instantiation_partial_context_line /home/heads/gcc/gcc-source/gcc/cp/error.c:3290 0x609eda print_instantiation_partial_context /home/heads/gcc/gcc-source/gcc/cp/error.c:3400 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/66153] Internal compiler error in nested template function 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk ` (2 preceding siblings ...) 2015-05-23 12:47 ` paboyle at ph dot ed.ac.uk @ 2021-12-21 21:11 ` pinskia at gcc dot gnu.org 2021-12-21 21:29 ` pinskia at gcc dot gnu.org ` (2 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-12-21 21:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |rejects-valid Severity|major |normal ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/66153] Internal compiler error in nested template function 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk ` (3 preceding siblings ...) 2021-12-21 21:11 ` pinskia at gcc dot gnu.org @ 2021-12-21 21:29 ` pinskia at gcc dot gnu.org 2021-12-21 21:45 ` pinskia at gcc dot gnu.org 2021-12-21 21:58 ` pinskia at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-12-21 21:29 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 --- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Reduced further: #include <type_traits> template <class T> struct TypeMapper { static const int NestLevel = T::NestLevel; }; template<> struct TypeMapper<double> { static const int NestLevel = 0; }; template<class obj> struct Container { obj data; }; template<class obj> struct Recursive { enum { NestLevel = TypeMapper<obj>::NestLevel + 1}; }; template<int N,class obj, typename std::enable_if<N==obj::NestLevel >::type * = nullptr > auto function(const obj &arg)-> obj { return arg; } template<int N,class obj, typename std::enable_if<N!=obj::NestLevel >::type * = nullptr > auto function(const obj &arg)-> obj { return obj{}; } template<int N,class obj> auto function(const Container<obj> & arg) -> Container<decltype(function<N>(arg.data))> { Container<Recursive<Recursive<double> > > ret; return ret; } int main(int argc,char **argv) { Container<Recursive<Recursive<double> > > array; Container<Recursive<Recursive<double> > > ret; function<1>(array); } ----- CUT ----- I have seen another one similar to this recently. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/66153] Internal compiler error in nested template function 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk ` (4 preceding siblings ...) 2021-12-21 21:29 ` pinskia at gcc dot gnu.org @ 2021-12-21 21:45 ` pinskia at gcc dot gnu.org 2021-12-21 21:58 ` pinskia at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-12-21 21:45 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 --- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Here is the full on reduced testcase (the previous one was wrong): template<class obj> struct Container { obj data[1]; }; template<class obj> struct Recursive {}; template<int N,class obj> obj function(const obj &arg) { return obj{}; } template<int N,class obj> auto function(const Container<obj> & arg) -> Container<decltype(function<N>(arg.data[0]))> { Container<decltype(function<N>(arg.data[0]))> ret; return ret; } int main(int argc,char **argv) { Container<Recursive<Recursive<int> > > array; function<1>(array); } ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/66153] Internal compiler error in nested template function 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk ` (5 preceding siblings ...) 2021-12-21 21:45 ` pinskia at gcc dot gnu.org @ 2021-12-21 21:58 ` pinskia at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-12-21 21:58 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66153 --- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> --- A little more reduced: template<class obj> struct c { obj data; }; struct r {}; template<int N,class obj> obj g(const obj &arg); template<int N,class obj> auto g(const c<obj> & arg) -> c<decltype(g<N>(arg.data))> { return c<decltype(g<N>(arg.data))>{}; } int main() { c<r > array; g<1>(array); } ---- CUT ---- Without the guide for the return type, GCC accepts the code. Somehow GCC is messing up g<N>, Removing the template argument N also allows GCC to accept the code. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-12-21 21:58 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-05-15 0:21 [Bug c++/66153] New: Internal compiler error in nested template function paboyle at ph dot ed.ac.uk 2015-05-15 11:42 ` [Bug c++/66153] " paboyle at ph dot ed.ac.uk 2015-05-16 4:41 ` paboyle at ph dot ed.ac.uk 2015-05-23 12:47 ` paboyle at ph dot ed.ac.uk 2021-12-21 21:11 ` pinskia at gcc dot gnu.org 2021-12-21 21:29 ` pinskia at gcc dot gnu.org 2021-12-21 21:45 ` pinskia at gcc dot gnu.org 2021-12-21 21:58 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).