http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48948
Summary: [C++0x] constexpr friend function cannot be defined
in-class
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
gcc 4.7.0 20110507 (experimental) in C++0x mode rejects the following code at
the line marked with #:
//---
struct B {
friend constexpr int f(B) { return 0; } // #
};
//---
"error: invalid type for parameter 1 of constexpr function 'constexpr int
f(B)'"
This code should be accepted.
The same problem occurs with friend operators, like this case
friend constexpr int operator+(B) { return 0; }
within B resulting in:
"error: invalid type for parameter 1 of constexpr function 'constexpr int
operator+(B)'"
It seems to me that this defect is *not* a dup of bug 48945, where the compiler
incorrectly attempts to add a const-qualifier to a static member function. I
can only assume that the compiler considers the argument as incomplete and thus
not being a valid literal type, because other non-friend constexpr functions
don't cause such problems, but I'm not sure.
Finally, the problem does not occur, if the friend function is defined
out-of-class, like so:
class C {
friend constexpr int g(C);
};
constexpr int g(C) { return 0; }