Is type qualifier on return type meaningless?

1 day ago 3
ARTICLE AD BOX

MSVC is wrong and the others are correct.

const has no effect in this case, but it is nevertheless part of the function template'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<class T> const auto f(T) { return 1; } const int(*x)(int) = f; // ok by all implementations

Ted Lyngmo's user avatar

2 Comments

Sidenote: The C++ standard has clear definition for the term "signature" and it does NOT include the function's return type for non-template functions. link

2026-03-31T06:54:47.177Z+00:00

@GKxx Indeed. The return type is included in the function template's signature (const auto f(auto) { return 1; }) but not in the function where the return type is deduced (without a template parameter) (const auto f(int) { return 1; }).

2026-03-31T07:28:44.177Z+00:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article