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

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> 
2011-05-10 16:33:39 UTC ---
(In reply to comment #1)

I don't think that this is intended, but I would like to await feedback from
the developer group before submitting a corresponding core issue. IMO there are
some core wordings in regard to type completeness that are not intended to be
read strictly, e.g. 3.2 p.4

"— a function with a return type or argument type of type T is defined (3.1)
[..]"

can be read to disallow any of the following function definitions:

struct A {
  A f(A a) { return a; }
  friend A g(A a) { return a; }
};

I haven't seen a compiler who rejects this code, because they all contribute
more weight to 9.2 p.2. In regard to constexpr functions the clear intention is
that these can be forward-declared and are only required to be completely
defined, if used in a manner that requires a constant expression. The example
in 7.1.5 with the constexpr function "small" and it's usage in the constexpr
constructor of pixel make this intention very clear. Now to me, the 3.2 p.4
requirement was always supposed to be interpreted as "complete as it would be
required to be complete within the function body" for both function parameters
and function return types within this function definition, so I don't see any
reason why the compiler needs to validate the constraints on literal types at
the point where the class type is still incomplete and *does* not need to be
complete.

If the gcc developer feedback indeed points to an intended conservative reading
of 3.2 p.4 for constexpr functions as in this example I will surely require to
open a core issue for this situation, because this severely constraints
constexpr function definitions within classes. In this case a simple workaround
is to replace the "by-value" parameter by "by-reference", but the need for such
a change looks like an artifact to me. It seems to me that both functions f()
and g() defined in class A above could be constexpr functions.

Reply via email to