[Bug c++/69261] [6 Regression] Copying char arrays during constexpr evaluation does not work reliably
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69261 --- Comment #4 from Jens Auer --- It produces the correct results if you change foo to not use constexpr: void foo() { auto const s1 = s( "bla" ); auto const s2 = s( "blu" ); string_constexpr<7> const s1s2 = concat(s1,s2); auto constexpr c = concat("bla", "blu"); std::cout << s1.data << std::endl << s2.data << std::endl << s1s2.data << std::endl << c << std::endl; } $ ./a.out bla blu blablu blablu
[Bug c++/69261] New: Copying char arrays during constexpr evaluation does not work reliably
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69261 Bug ID: 69261 Summary: Copying char arrays during constexpr evaluation does not work reliably Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jens.auer at cgi dot com Target Milestone: --- Created attachment 37331 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37331=edit Preprocessed source code I was playing around with string processing for constexpr values, and wrote the following program to concatenate two strings at compile time: #include #include #include using std::size_t; template struct string_constexpr { constexpr string_constexpr() = default; template constexpr string_constexpr( char const ()[M] ): data{0} { static_assert( M <= N, "size!" ); for(size_t i=0; i != M; i++) { data[i] = d[i]; } } char data[N]; }; template T& operator<<(T& stream, string_constexpr const& str) { return (stream << str.data); } template constexpr string_constexpr s( char const ()[N] ) { string_constexpr c{}; for(size_t i=0; i != N; i++) { c.data[i] = d[i]; } return c; } template constexpr auto concat(string_constexpr const& s1, string_constexpr const& s2) { string_constexpr<N+M-1> s( s1.data ); for(size_t i=0; i != M; i++) { s.data[N+i-1] = s2.data[i]; } return s; } template constexpr auto concat(char const ()[N], char const ()[M]) { string_constexpr<N+M-1> tmp{x}; for(size_t i=0; i != M; i++) { tmp.data[N+i-1] = y[i]; } return tmp; } void foo() { auto constexpr s1 = s( "bla" ); auto constexpr s2 = s( "blub" ); string_constexpr<8> constexpr s1s2 = concat(s1,s2); auto constexpr c = concat("bla", "blub"); std::cout << s1.data << std::endl << s2.data << std::endl << s1s2.data << std::endl << c << std::endl; } int main() { foo(); return 0; } Executables compiled with GCC and clang produce different outputs, and I think clang is right: $ g++ -std=c++1y static_strings.cpp $ ./a.out bla blub blablub $ clang++ -std=c++1y static_strings.cpp $ ./a.out bla blub blablub blablub
[Bug c++/69263] New: internal compiler error: in cxx_eval_store_expression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69263 Bug ID: 69263 Summary: internal compiler error: in cxx_eval_store_expression Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jens.auer at cgi dot com Target Milestone: --- Compilation of the following program with gcc 6.0.0 201601 (from the online compiler http://melpon.org/wandbox, http://melpon.org/wandbox/permlink/CMreVotFuJMgnuI7) crashes: #include #include #include using std::size_t; template struct string_constexpr { constexpr string_constexpr() = default; template constexpr string_constexpr( char const ()[M] ): data{0} { static_assert( M <= N, "size!" ); for(size_t i=0; i != M; i++) { data[i] = d[i]; } } char data[N]; }; template T& operator<<(T& stream, string_constexpr const& str) { return (stream << str.data); } template constexpr string_constexpr s( char const ()[N] ) { string_constexpr c{}; for(size_t i=0; i != N; i++) { c.data[i] = d[i]; } return c; } template constexpr auto concat(string_constexpr const& s1, string_constexpr const& s2) { string_constexpr<N+M-1> s( s1.data ); for(size_t i=0; i != M; i++) { s.data[N+i-1] = s2.data[i]; } return s; } template constexpr auto concat(char const ()[N], char const ()[M]) { static_assert(N == 4 && M == 4, ""); string_constexpr<N+M-1> tmp{x}; for(size_t i=0; i != M; i++) { tmp.data[N+i-1] = y[i]; } return tmp; } void foo() { auto constexpr s1 = s( "bla" ); auto constexpr s2 = s( "blub" ); string_constexpr<8> constexpr s1s2 = concat(s1,s2); auto constexpr c = concat("bla", "blub"); std::cout << s1.data << std::endl << s2.data << std::endl << s1s2.data << std::endl << c << std::endl; } int main() { foo(); return 0; } g++ prog.cc -Wall -Wextra -std=gnu++1z prog.cc: In function 'void foo()': prog.cc:74:33: in constexpr expansion of 's<4>("bla")' prog.cc:74:33: internal compiler error: in cxx_eval_store_expression, at cp/constexpr.c:2808 auto constexpr s1 = s( "bla" ); ^ 0x6f249e cxx_eval_store_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:2808 0x6f03bb cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3312 0x6efc5f cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3570 0x6f0267 cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3349 0x6f0267 cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3349 0x6f2b21 cxx_eval_statement_list /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3028 0x6f0563 cxx_eval_loop_expr /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3055 0x6f0563 cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3680 0x6f2b21 cxx_eval_statement_list /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3028 0x6f044c cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3614 0x6efd2f cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3669 0x6f2b21 cxx_eval_statement_list /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3028 0x6f044c cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3614 0x6efd2f cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3669 0x6ef1df cxx_eval_call_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:1386 0x6efd0b cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3238 0x6f0c7a cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3296 0x6efedb cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3378 0x6efc5f cxx_eval_constant_expression /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3570 0x6f2cf8 cxx_eval_outermost_constant_expr /home/heads/gcc/gcc-source/gcc/cp/constexpr.c:3773 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. 1 Finish
[Bug c++/69263] internal compiler error: in cxx_eval_store_expression
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69263 --- Comment #1 from Jens Auer --- The source code is same as in bug #69261. On gcc 5.2, it compiles but produces a different output than a program compiled with clang. I have opened two separate bug reports because the effects are different and it affects two different versions, but feel free to merge them if it makes sense.
[Bug c++/69261] Copying char arrays during constexpr evaluation does not work reliably
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69261 --- Comment #2 from Jens Auer --- I have submitted a second bug report for the crash: Bug 69263. I don't know if that was appropriate, but the bug has different effects on different versions.
[Bug c++/67951] New: Wshadow for type inferenced (auto) lambda parameters
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67951 Bug ID: 67951 Summary: Wshadow for type inferenced (auto) lambda parameters Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jens.auer at cgi dot com Target Milestone: --- int f() { auto l = [](int i) {}; int i=0; l(i); return i; } void h() { auto l = [](auto i) {}; int i=0; l(i); } If compiled with "g++ -std=c++1y -Wshadow", I get a warning in h: shadow.cpp:15:23: warning: declaration of ‘i’ shadows a previous local [-Wshadow] auto l = [](auto i) {}; ^ shadow.cpp:17:9: note: shadowed declaration is here int i=0; I think this is wrong. If it is not wrong, it is inconsistent because there is no warning in f().
[Bug c++/67952] New: Compilation error with boost::signals2 and generic lambda: cannot call member function without object
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67952 Bug ID: 67952 Summary: Compilation error with boost::signals2 and generic lambda: cannot call member function without object Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jens.auer at cgi dot com Target Milestone: --- Created attachment 36495 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36495=edit Preprocessed source code The following code doesn't compile with boost 1.59 and gcc 5.1, but with clang 3.6: #include class A { public: A() { // these two work sig2.connect( [this]() {f();} ); sig.connect( [this](auto x) {this->g(x);} ); // this does not work sig.connect( [this](auto x) {g(x);} ); } private: void f(); void g(int); boost::signals2::signal sig; boost::signals2::signal sig2; }; The error message is shadow.cpp: In instantiation of ‘A::A()::<lambda(auto:2)> [with auto:2 = int]’: /lhome1/auerj/opt/include/boost/function/function_template.hpp:153:11: required from ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = A::A()::<lambda(auto:2)>; R = void; T0 = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:934:38: required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:722:7: required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral::value)>::value), int>::type) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral::value)>::value), int>::type = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:1071:16: required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral::value)>::value), int>::type) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral::value)>::value), int>::type = int]’ /lhome1/auerj/opt/include/boost/function/function_template.hpp:1126:5: required from ‘typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral::value)>::value), boost::function<R(T0)>&>::type boost::function<R(T0)>::operator=(Functor) [with Functor = A::A()::<lambda(auto:2)>; R = void; T0 = int; typename boost::enable_if_c<(boost::type_traits::ice_not<(boost::is_integral::value)>::value), boost::function<R(T0)>&>::type = boost::function<void(int)>&]’ /lhome1/auerj/opt/include/boost/signals2/detail/slot_template.hpp:160:24: required from ‘void boost::signals2::slot<R(Args ...), SlotFunction>::init_slot_function(const F&) [with F = A::A()::<lambda(auto:2)>; SlotFunction = boost::function<void(int)>; R = void; Args = {int}]’ /lhome1/auerj/opt/include/boost/signals2/detail/slot_template.hpp:85:27: required from ‘boost::signals2::slot<R(Args ...), SlotFunction>::slot(const F&) [with F = A::A()::<lambda(auto:2)>; SlotFunction = boost::function<void(int)>; R = void; Args = {int}]’ shadow.cpp:13:45: required from here shadow.cpp:13:38: error: cannot call member function ‘void A::g(int)’ without object sig.connect( [this](auto x) {g(x);} ); I think it is a compiler bug because adding the implicit this-> solves the problem (see second connect). My gcc version: g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/lhome1/auerj/opt/libexec/gcc/x86_64-unknown-linux-gnu/5.1.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-5.1.0/configure --prefix=/lhome1/auerj/opt --enable-languages=c,c++ Thread model: posix gcc version 5.1.0 (GCC) I have attached the preprocessed output so it should be easy to reproduce the issue. It is probably a duplicate of 61636, but I such that it can be tracked as such. I guess boost::signals2 is a popular library, so it may be worth to have it in the database explicitly.
[Bug middle-end/60725] [-Wreturn-type] false positive in trivial switch
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60725 Jens Auer changed: What|Removed |Added CC||jens.auer at cgi dot com --- Comment #2 from Jens Auer --- This warnings becomes annoying when you also compile with -Wswitch-enum which forces you to cover all enum values. When they are all covered, I do not need a default statement, but to prevent Wreturn-type, I have to add a pseudo-default.