Hi Honza, While testing improvements to GCC attribute handling I came across the warning below:
In file included from /ssd/src/gcc/81544/libstdc++-v3/src/c++98/mt_allocator.cc:31:0: /ssd/build/gcc-81544/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/mt_allocator.h:359:43: warning: ‘const’ attribute on function returning ‘void’ [-Wattributes]
_M_destroy_thread_key(void*) throw (); ^ Git log shows you added the attribute in r146330 and there was a lively debate preceding the change on the libstdc++ mailing list: https://gcc.gnu.org/ml/libstdc++/2009-04/msg00053.html A patch including this function was posted here: https://gcc.gnu.org/ml/libstdc++/2009-04/msg00111.html I've re-read much of the discussion but couldn't find my answer there so I'm wondering if you could help me understand the rationale for it. (Btw., I understand what the attribute does, I'm just not sure why it's helpful or even used in this instance. The function is declared like this in the header: // XXX GLIBCXX_ABI Deprecated _GLIBCXX_CONST void _M_destroy_thread_key(void*) throw (); and defined like so in mt_allocator.cc: void __pool<true>::_M_destroy_thread_key(void*) throw () { } So the definition trivially meets the requirements on a const function, and calls to it will be eliminated (with optimization). My question is: since the function is deprecated and its definition only provided for ABI compatibility, should calls to it ever actually be compiled with future revisions of GCC? I mean, since it's an implementation-only function, there should be no code outside of libstdc++ that makes direct calls to it. Code that did make calls to it (e.g., as a result of macro or inline expansion) was presumably compiled into object files by older versions of GCC (before the deprecation and before the addition of the attribute) and won't benefit from the const attribute now. And since the function is deprecated, no code newly compiled with GCC should make calls to it, either directly or otherwise. (Would using attribute deprecated on the function make sense?) The reason for my question is to understand if the warning is justified (it's based on the documentation of attribute const: "It does not make sense for a const function to return void.") If it does make sense to declare a function const that returns void then I'll remove the warning and update the manual and mention this use case. Otherwise, if you confirm that the function shouldn't be called in new code I'll submit a patch to remove the const attribute. Thanks Martin