This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71463] "ignoring attributes on template argument" in -O1 and above
- From: "mail at milianw dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 09 Jun 2016 09:05:32 +0000
- Subject: [Bug c++/71463] "ignoring attributes on template argument" in -O1 and above
- Auto-submitted: auto-generated
- References: <bug-71463-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71463
--- Comment #2 from Milian Wolff <mail at milianw dot de> ---
Indeed, there is a difference between malloc in the two levels:
-O0:
~~~~~~~~~~~~
extern void *malloc (size_t __size) throw () __attribute__ ((__malloc__)) ;
~~~~~~~~~~~~
-O1:
~~~~~~~~~~~~
extern void *malloc (size_t __size) throw () __attribute__ ((__malloc__))
__attribute__ ((__warn_unused_result__));
~~~~~~~~~~~~
This simplifies the testcase to:
~~~~~~~~~~~~
void* malloc() __attribute__ ((__warn_unused_result__));
template<typename Ptr> struct foo {};
foo<decltype(&malloc)> emit_unexpected_warning;
int main() { return 0; }
~~~~~~~~~~~~
So, do you say this warning is an expected result? I find it highly unexpected.
Can I silence this warning somehow?
Also, how come that `decltype()` is able to return me a type including the
attributes, when these are not storable in the type system? Is that maybe the
root of the issue here? Or are there cases where one needs to access the
attributes via decltype? I can't think of a way to compare / access that
information then.
Any input would be appreciated, thanks!