http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56693



             Bug #: 56693

           Summary: Fail to ignore const qualification on top of a

                    function type.

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: cassio.n...@gmail.com





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

Reply via email to