[Bug c++/58798] class with a class reference member generates unjustified warning

2021-10-27 Thread olafvdspek at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798

Olaf van der Spek  changed:

   What|Removed |Added

 CC||olafvdspek at gmail dot com

--- Comment #9 from Olaf van der Spek  ---
Any conclusions?
Could classes with references be packed?

[Bug c++/58798] class with a class reference member generates unjustified warning

2019-05-25 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798

--- Comment #8 from Jonathan Wakely  ---
(In reply to Szikra from comment #3)
> 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. :(

I'm pretty sure Clang copied that feature from GCC:


https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas

[Bug c++/58798] class with a class reference member generates unjustified warning

2019-05-25 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798

Eric Gallager  changed:

   What|Removed |Added

 Blocks||44209

--- Comment #7 from Eric Gallager  ---
This is an example of bug 44209


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44209
[Bug 44209] [meta-bug] Some warnings are not linked to diagnostics options

[Bug c++/58798] class with a class reference member generates unjustified warning

2017-08-25 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798

Eric Gallager  changed:

   What|Removed |Added

   Keywords||diagnostic
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-08-25
 CC||egallager at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #6 from Eric Gallager  ---
(In reply to Szikra from comment #5)
> (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?

Confirmed that the warning should be controlled by -Wpacked. I also noticed
this in bug 60972.

[Bug c++/58798] class with a class reference member generates unjustified warning

2017-01-30 Thread steven.spark at gmail dot com
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

2017-01-29 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58798

--- Comment #4 from Jonathan Wakely  ---
(In reply to Szikra from comment #3)
> 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?

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.

If the warning was controlled by an option you could suppress it with -Wno-xxx
or a #pragma.

[Bug c++/58798] class with a class reference member generates unjustified warning

2017-01-29 Thread steven.spark at gmail dot com
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

2017-01-29 Thread steven.spark at gmail dot com
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=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

2017-01-29 Thread steven.spark at gmail dot com
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) { /// fake Set
data_= val;return *this;
}
private:
T& data_;
};

template
inline EepromAccessor Eeprom(T& data)
{
EepromAccessor eepromdata(data);
return eepromdata;
}

unsigned int EEMEM test;
int main()
{
Eeprom(test) = 32;
unsigned int r = Eeprom(test);

//cout << " eeprom: "