https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92752
Bug ID: 92752
Summary: Bogus "ignored qualifiers" warning on const-qualified
pointer-to-member-function objects
Product: gcc
Version: 9.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: alisdairm at me dot com
Target Milestone: ---
We are seeing a bogus warning on the default constructor for a class template
that wraps a data member of the template parameter type, when that template
parameter is a const-qualified pointer-to-member-function type (note, the
pointer-to-member function type is cv-qualified, not the member function that
is pointed to). This comes up in our own library implementation for a
pair-like type used for our associative containers (pair<const Key, Value>)
Example code, should be compiled with -Wextra to show the warning:
struct X {};
using MemFn = int (X::*)();
template <class T>
struct Wrap {
T data;
Wrap() : data() {}
};
int main() {
Wrap<MemFn const> x;
}
Compiler output:
In instantiation of 'Wrap<T>::Wrap() [with T = int (X::* const)()]':
13:23: required from here
9:29: warning: type qualifiers ignored on cast result type
[-Wignored-qualifiers]
9 | Wrap() : data() {}
| ^
Compiler returned: 0
As far as we can tell, this applies only to pointer-to-member-function types,
not regular function pointers, not pointer-to-data-member, nor any other scalar
type.
Checking past compilers with the Godbolt compiler explorer, this warning seems
to first appear in gcc 8.1:
https://godbolt.org/z/8Mxpsm