[Bug libstdc++/60594] std::function of a type with a declared (but not defined) return type fails to compile

daniel.kruegler at googlemail dot com gcc-bugzilla@gcc.gnu.org
Wed Mar 19 21:22:00 GMT 2014


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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #4 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
(In reply to Jonathan Wakely from comment #1)
> Are you sure this is valid?

I tend to say it is valid, see below for a further comment on this.

> Instantiating std::function (like most std::lib
> templates) with an incomplete type is undefined behaviour. Is the function
> type bar() complete if bar is not complete?

This is definitively true (i.e. bar() is a complete type), because function
types are not affected by the definition of complete types, 3.9 p. says:

"Incompletely defined object types and the void types are incomplete types
(3.9.1)."

I would say that the definition of "INVOKE(f, t1, t2, ..., tN, R)" is not
well-defined for incomplete R (except when R==void) due to the
"implicitly-convertible" constraint mentioned in 20.9.2 p2, but 20.9.11 doesn't
seem to impose this constraint to hold when instantiating a std::function<>. On
the other hand the current std::function wording clearly is underspecified:
There are several members that would require R to be a complete type. I don't
think that the default constructor is one of these, though. Among the members
where this is needed is IMO

template<class F> function(F f);

because the compile-time constraint

"unless f is Callable (20.9.11.2) for argument types ArgTypes... and return
type R."

can only be deduced, if R is complete (modulo void again).


More information about the Gcc-bugs mailing list