Bug 56693 - [DR 1584] Fail to ignore const qualification on top of a function type.
Summary: [DR 1584] Fail to ignore const qualification on top of a function type.
Status: SUSPENDED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-22 23:30 UTC by Cassio Neri
Modified: 2021-08-13 17:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-03-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cassio Neri 2013-03-22 23:30:13 UTC
The following code:

void f() {}

template <typename T> void g(const T*) { }

int main() {
    g(f);
}

raises an error with this note:

    types 'const T' and 'void()' have incompatible cv-qualifiers

Attempting to instantiate g creates a function that takes a pointer to a const T where T = void(). Since there's no such thing as a "const function", this explains the note. However, C++11 8.3.5/6 says

"The effect of a cv-qualifier-seq in a function declarator is not the same as adding cv-qualification on top of the function type. In the latter case, the cv-qualifiers are ignored."

Hence, the const qualifier should be ignored and the code should compile. (It does compile with clang and visual studio.)

For more information see:
http://stackoverflow.com/questions/15578298/can-a-const-t-match-a-pointer-to-free-function
Comment 1 Daniel Krügler 2013-03-23 12:20:30 UTC
This looks like

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1584

to me
Comment 2 Andrew Pinski 2021-08-12 04:06:40 UTC
Notes from the May, 2015 meeting:

The consensus of CWG was that the cv-qualification of the argument and parameter must match, so the original example should be rejected.