[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: possibly a bug in g++



> Please answer somebody wether it is a bug and wether I should submit it to
> GNATS.

I believe this is not a bug, because there are no const-qualified
function types in C++.

If you don't agree, please let us known what you think the value of
TFunc is. IMO, the only reasonable assumption is that it is tfunc_t as
in

typedef void (tfunc_t)(int, int);

Then, the argument type would be

typedef const tfunc_t & afunc_t;

in

void tpl_func(afunc_t func);

However, this creates a const-qualified function type, which is
impossible.

More specifically, 14.8.2/2 specifies

# All references in the function type of the function template to the
# corresponding template parameters are replaced by the specified
# template argument values. If a substitution in a template parameter
# or in the function type of the function template results in an
# invalid type, type deduction fails. ... Type deduction may fail for
# the following reasons:
...
# - Attempting to create a cv-qualified function type.

So the compiler first deduces that tfunc_t would be the template
parameter. It then puts it into the signature, and finds that this
would create an invalid type. Thus, template argument deduction fails.
This, in itself, is not an error - it just means that this template is
not a candidate for overload resolution anymore. The program is then
rejected since no other function matches, either.

It seems gcc 2.95 accepted this code since it did not worry about
creating const-qualified function types, so it erroneously accepted
the code.

Of course, this is difficult matter, so you may want to ask
comp.std.c++ for further comments.

Regards,
Martin



Reply to: