This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58798] class with a class reference member generates unjustified warning
- From: "steven.spark at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 29 Jan 2017 15:45:29 +0000
- Subject: [Bug c++/58798] class with a class reference member generates unjustified warning
- Auto-submitted: auto-generated
- References: <bug-58798-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798
Szikra <steven.spark at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |steven.spark at gmail dot com
--- Comment #1 from Szikra <steven.spark at gmail dot com> ---
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<long unsigned int>':
../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<long
unsigned int>::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<unsigned int>':
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<unsigned
int>::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 <iostream>
//using namespace std;
#define EEMEM /// fake
template<typename T>
class EepromAccessor {
public:
EepromAccessor(T& data) : data_(data) {};
inline operator T() { return (data_); } /// fake Get
inline EepromAccessor<T>& operator=(const T& val) { /// fake Set
data_= val; return *this;
}
private:
T& data_;
};
template<typename T>
inline EepromAccessor<T> Eeprom(T& data)
{
EepromAccessor<T> eepromdata(data);
return eepromdata;
}
unsigned int EEMEM test;
int main()
{
Eeprom(test) = 32;
unsigned int r = Eeprom(test);
// cout << " eeprom: " << test << endl;
return r!=32;
}
Same issue here:
https://github.com/bblanchon/ArduinoJson/issues/255