[Bug c++/55227] designated initializer for char array by string constant
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55227 Szikra changed: What|Removed |Added CC||steven.spark at gmail dot com --- Comment #5 from Szikra --- I just run into this problem with gcc version 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] (GNU Tools for Arm Embedded Processors 7-2018-q2-update) Thanks J.R. Heisey and ensadc, the extra braces solved the error... for now. I added this url to comments in case this bug is fixed and they need to be removed. typedef struct { /// ... uint16_t serverPort; char serverAddress[128]; } ConfigParameters_t; ConfigParameters_t __attribute__((section(".eeprom"))) eeParameters = { /// ... .serverPort=1234, {.serverAddress="*"} /// weird... https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55227 };
[Bug c++/49974] missing warning for indirectly returning reference to local/temporary
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49974 --- Comment #8 from Szikra --- (In reply to Marc Glisse from comment #7) > We currently warn on all the examples involving X, with -O2. We don't for Y, > we might if there was a caller and the dangling reference was used there... Hi, I assume you mean like this: #include using namespace std; struct Y { Y(int& i) : r(i) { } int& r; }; Y f() { int i=1; return Y(i); } int main() { Y y1= f(); cout << y1.r << endl; /// warning: 'i' is used uninitialized in this function [-Wuninitialized] } /* compiled with gcc version 6.3.0 (x86_64-posix-seh-rev1, Built by MinGW-W64 project) g++ -std=c++11 -O2 -g3 -Wall -Wextra -Wconversion -c -fmessage-length=0 -v -o "src\\test3.o" "..\\src\\test3.cpp" */ What about this? struct Y2 { Y2(const int& i) : r(i) { } const int& r; }; We might or might not get a warning even if the reference is used. int main() { Y2 y2(2); cout << y2.r << endl; /// warning: '' is used uninitialized in this function [-Wuninitialized] } and Y2 g_y2(22); int main() { cout << g_y2.r << endl; /// no warning at all } Or what about this? struct Z { Z(int i) : r(i) { } int& r; }; Z g_z(33); int main() { cout << g_z.r << endl; /// no warning Z z(3); cout << z.r << endl; /// no warning }
[Bug c++/79307] g++ misses warning for reference on temporary that invokes undefined behaviour
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79307 --- Comment #4 from Szikra --- > This is bug 44974. > > > Possible duplicate of bug #44859 or bug #51270. > > Looks more like bug 49974 to me. > > *** This bug has been marked as a duplicate of bug 44974 *** Hi you are right, my first example is the same as in bug 49974: struct Y { Y(int& i) : r(i) { } int& r; }; If that were fixed, it would probably solve both problem. Though my second case might be easier to detect, or it's more obviously wrong :) struct TestRefIntDirect { TestRefIntDirect(int a) : a_(a) {}; const int& a_; }; This is wrong by in itself, in this case temporary is always created and in the same place where it is used. But I have a problem: Shouldn't this be marked as duplicate of bug 49974 and not bug 44974? :)
[Bug c++/79307] New: g++ misses warning for reference on temporary that invokes undefined behaviour
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79307 Bug ID: 79307 Summary: g++ misses warning for reference on temporary that invokes undefined behaviour Product: gcc Version: 5.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: steven.spark at gmail dot com Target Milestone: --- I thought (something like) this was fixed in bug 986 Code: struct TestRefInt { TestRefInt(const int& a) : a_(a) {}; void DoSomething() {cout << "int:" << a_ << endl; } protected: const int& a_; }; TestRefInt tfi(55); int main() { TestRefInt ltfi(8); tfi.DoSomething(); ltfi.DoSomething(); return 0; } The first one does not work, the second one happens to work (but only by "accident"). Similar issue: struct TestRefIntDirect { TestRefIntDirect(int a) : a_(a) {}; void DoSomething() {cout << "int:" << a_ << endl; } protected: const int& a_; }; Lifetime of the temporary is not extended in neither case (as per C++11 standard 12.2 p5). Tested with MinGW 5.3.0, avr-g++ 4.8.1, 4.9.2. I would like if warning were produced for these. Any help would be appreciated. I posted more details on stack overflow http://stackoverflow.com/questions/41928634/c11-scoping-and-lifetime-of-temporary-bound-to-a-const-reference-gcc Possible duplicate of bug #44859 or bug #51270.
[Bug c++/58798] class with a class reference member generates unjustified warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798 --- Comment #5 from Szikra --- (In reply to Jonathan Wakely from comment #4) > Because the warning isn't controlled by the -Wpacked option. If it was, it > would say [-Wpacked] after the warning. I think that's a bug, every warning > should be controlled by some -Wxxx option. Thanks, good to know. So does this require a separate bug report, or can someone change the status and confirm this one?
[Bug c++/58798] class with a class reference member generates unjustified warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798 --- Comment #3 from Szikra --- The warning is still there if I use the -Wno-packed option: g++ -std=gnu++11 -fpack-struct -Wno-packed eeprom.cpp -o eeprom Why? I have found a suggestion to hide warning about ignored attributes: #pragma clang diagnostic ignored "-Wignored-attributes" which doesn't seem to have a GCC equivalent. :(
[Bug c++/58798] class with a class reference member generates unjustified warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798 --- Comment #2 from Szikra --- Created attachment 40615 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40615&action=edit preprocessed test case Compiled with g++ --save-temps -std=gnu++11 -fpack-struct eeprom.cpp -o eeprom eeprom.cpp: In instantiation of 'class EepromAccessor': eeprom.cpp:29:16: required from here eeprom.cpp:16:8: warning: ignoring packed attribute because of unpacked non-POD field 'unsigned int& EepromAccessor::data_' T& data_; ^
[Bug c++/58798] class with a class reference member generates unjustified warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798 Szikra changed: What|Removed |Added CC||steven.spark at gmail dot com --- Comment #1 from Szikra --- I'm having a similar issue. Got here from here: http://stackoverflow.com/questions/35152877/ignoring-packed-attribute-because-of-unpacked-non-pod-field I'm not sure if this is a bug or not, I'm looking ways to get rid of the warning message. (without removing -fpack-struct from the command line) How can I do that? Any '#pragma GCC diagnostic ignored' I can use? My compiler output looks something like this: ...common/eeprom.hpp: In instantiation of 'class FromEeprom::EepromAccessor': ../src/test.cpp:193:29: required from here …common/eeprom.hpp:119:8: warning: ignoring packed attribute because of unpacked non-POD field 'long unsigned int& FromEeprom::EepromAccessor::data_' [enabled by default] GCC Versions: AVR8/GNU C Compiler : 4.8.1, 4.9.2 (latest I could find for AVR on Windows) similar result with MinGW 5.3: g++ -std=gnu++11 -fpack-struct eeprom.cpp -o eeprom from test/eeprom.cpp:19: ./common/eeprom.hpp: In instantiation of 'class FromEeprom::EepromAccessor': test/eeprom.cpp:30:16: required from here ./common/eeprom.hpp:119:8: warning: ignoring packed attribute because of unpacked non-POD field 'unsigned int& FromEeprom::EepromAccessor::data_' T& data_; But with the added errors: In file included from C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/ios:42:0, from C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/ostream:38, from C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/iostream:39, from test/eeprom.cpp:23: C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h: In member function 'std::ios_base::fmtflags std::ios_base::setf(std::ios_base::fmtflags)': C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h:649:7: error: cannot bind packed field '((std::ios_base*)this)->std::ios_base::_M_flags' to 'std::_Ios_Fmtflags&' _M_flags |= __fmtfl; ^ C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h: In member function 'std::ios_base::fmtflags std::ios_base::setf(std::ios_base::fmtflags, std::ios_base::fmtflags)': C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h:666:7: error: cannot bind packed field '((std::ios_base*)this)->std::ios_base::_M_flags' to 'std::_Ios_Fmtflags&' _M_flags &= ~__mask; ^ C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h:667:7: error: cannot bind packed field '((std::ios_base*)this)->std::ios_base::_M_flags' to 'std::_Ios_Fmtflags&' _M_flags |= (__fmtfl & __mask); ^ C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h: In member function 'void std::ios_base::unsetf(std::ios_base::fmtflags)': C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h:679:7: error: cannot bind packed field '((std::ios_base*)this)->std::ios_base::_M_flags' to 'std::_Ios_Fmtflags&' { _M_flags &= ~__mask; } ^ C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h: In member function 'long int& std::ios_base::iword(int)': C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h:813:21: error: cannot bind packed field '__word.std::ios_base::_Words::_M_iword' to 'long int&' return __word._M_iword; ^ C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h: In member function 'void*& std::ios_base::pword(int)': C:/mingw-w64/x86_64-5.3.0-posix-seh-rt_v4-rev0/mingw64/x86_64-w64-mingw32/include/c++/bits/ios_base.h:834:21: error: cannot bind packed field '__word.std::ios_base::_Words::_M_pword' to 'void*&' return __word._M_pword; ^ Here is a code to reproduce: //#include //using namespace std; #define EEMEM /// fake template class EepromAccessor { public: EepromAccessor(T& data) : data_(data) {}; inline operator T() { return (data_);} /// fake Get inline EepromAccessor& operator=(const T& val) { ///
[Bug c++/70774] New: constexpr function with reference parameter gives reinterpret_cast from integer to pointer error
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70774 Bug ID: 70774 Summary: constexpr function with reference parameter gives reinterpret_cast from integer to pointer error Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: steven.spark at gmail dot com Target Milestone: --- Here is the simplified code: -- #define PORTX (*(volatile unsigned char *)(0x1B)) constexpr volatile unsigned char * testRef(volatile unsigned char & x) { return &x; } volatile unsigned char* addr = testRef(PORTX); /// OK constexpr volatile unsigned char* addr2 = testRef(PORTX); /// error: /// reinterpret_cast from integer to pointer -- This compiled without problem with gcc 4.8.1, but fails with 4.9.2. Using built-in specs. COLLECT_GCC=avr-g++.exe Target: avr Configured with: /home/toolsbuild/workspace/avr8-gnu-toolchain/src/gcc/configure LDFLAGS=-L/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs/lib CPPFLAGS= --target=avr --host=i686-w64-mingw32 --build=x86_64-pc-linux-gnu --prefix=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86 --libdir=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86/lib --enable-languages=c,c++ --with-dwarf2 --enable-doc --disable-shared --disable-libada --disable-libssp --disable-nls --with-avrlibc=yes --with-mpfr=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-gmp=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --with-mpc=/home/toolsbuild/workspace/avr8-gnu-toolchain/avr8-gnu-toolchain-win32_x86-hostlibs --enable-win32-registry=avrtoolchain --with-pkgversion=AVR_8_bit_GNU_Toolchain_3.5.0_1662 --with-bugurl=http://www.atmel.com Thread model: single gcc version 4.9.2 (AVR_8_bit_GNU_Toolchain_3.5.0_1662) I'm writing code for AVR micro controller where every byte counts, so compile time evaluation is key. I was trying out the new Atmel Studio 7 IDE which comes with the new 4.9.2 gcc when I came across this problem. In my real world code I'm using constexpr constructor and constexpr instances of my pin handler class - to make life easier and encapsulate port, data direction and other registers. Note: If I use pointer instead of reference then it compiles fine: constexpr volatile unsigned char * testAddr(volatile unsigned char * x) { return x; } constexpr volatile unsigned char* addr3 = testAddr(&PORTX); /// OK Why is this? Am I doing something wrong? How can I use (port) references in constexpr functions? This also does NOT work: constexpr volatile unsigned char& ref5 = PORTX; /// error
[Bug c/61813] New: __attribute__((__packed__)) does not pack struct containing uint16_t with uint32_t
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61813 Bug ID: 61813 Summary: __attribute__((__packed__)) does not pack struct containing uint16_t with uint32_t Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: steven.spark at gmail dot com Created attachment 33125 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33125&action=edit preprocessed bugreport_packed.c Test case: typedef struct __attribute__((__packed__)) { uint16_t a;/// 2 uint32_t b; /// +4 uint32_t c[8]; /// +4*8 = 38 } foo_t; but the size of foo_t is 40 (instead of the 38 which it should be). (It does not matter where I put the packed attribute.) I'm using the latest released mingw to date (4.8.1 rev 5). I'm compiling on Windows 7 x64 (with mingw). GCC config: Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-4.8.1/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/tmp/x64-481-win32-seh-r5/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpfr=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpc=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-isl=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-cloog=/tmp/mingw-prereq/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='rev5, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/tmp/x64-481-win32-seh-r5/libs/lib -L/tmp/mingw-prereq/x64-zlib/lib -L/tmp/mingw-prereq/x86_64-w64-mingw32-static/lib -L/tmp/x64-481-win32-seh-r5/mingw64/opt/lib ' Thread model: win32 gcc version 4.8.1 (rev5, Built by MinGW-W64 project) command line gcc bugreport_packed.c or gcc -v -save-temps -Wall -Wextra bugreport_packed.c complete comiler output: Using built-in specs. COLLECT_GCC=C:\MinGW\x64-4.8.1-win32-seh-rev5\mingw64\bin\gcc COLLECT_LTO_WRAPPER=c:/mingw/x64-4.8.1-win32-seh-rev5/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-4.8.1/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/tmp/x64-481-win32-seh-r5/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpfr=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-mpc=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-isl=/tmp/mingw-prereq/x86_64-w64-mingw32-static --with-cloog=/tmp/mingw-prereq/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='rev5, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/tmp/x64-481-win32-seh-r5/libs/include -I/tmp/mingw-prereq/x64-zlib/include -I/tmp/mingw-prereq/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/tmp/x64-481-win32-seh-r5/libs/lib -L/tmp/mingw-prereq/x64-zlib/lib -L/tmp/mingw-prereq/x86_64-w64-mingw32-static/lib -L/tmp/x64-481-win32-seh-r5/mingw64/opt/lib ' Thread model: