Question Details

No question body available.

Tags

c++ constants function-pointers return-type function-templates

Answers (1)

March 30, 2026 Score: 4 Rep: 125,437 Quality: Medium Completeness: 60%

MSVC is wrong and the others are correct.

const has no effect in this case, but it is nevertheless part of the function's signature.

MSVC somehow forgets that the meaningless const is part of the signature when it comes to this assignment:

const auto f(auto) { return 1; }
int(x)(int) = f;

So, MSVC accepts it, while the other implementations rightfully reject it.

MSVC is also inconsistent. It only seems to reject the assignment if it's a function template with a deduced return type:

const auto f(int) { return 1; }  // ok (only deduced return type)
const int f(auto) { return 1; }  // ok (only function template)
const auto f(auto) { return 1; } // NOK (both)
//
const int(x)(int) = f;

It does, however, accept old-school template arguments:

template
const auto f(T) { return 1; }

const int(*x)(int) = f; // ok by all implementations