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!