Fixes for -preview=rvaluerefparam (#9092)

* Update `hasToString` for `-preview=rvaluerefparam`

* Remove ref parameter test of parse()
This commit is contained in:
Dennis 2024-11-27 07:29:24 +01:00 committed by GitHub
parent 6b666971bc
commit 600c721875
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 17 deletions

View file

@ -2560,9 +2560,6 @@ Lerr:
string s1 = "123";
auto a1 = parse!(int, string, Yes.doCount)(s1);
assert(a1.data == 123 && a1.count == 3);
// parse only accepts lvalues
static assert(!__traits(compiles, parse!int("123")));
}
///

View file

@ -1839,24 +1839,26 @@ template hasToString(T, Char)
else static if (is(typeof(
(T val) {
const FormatSpec!Char f;
static struct S {void put(scope Char s){}}
static struct S
{
@disable this(this);
void put(scope Char s){}
}
S s;
val.toString(s, f);
static assert(!__traits(compiles, val.toString(s, FormatSpec!Char())),
"force toString to take parameters by ref");
static assert(!__traits(compiles, val.toString(S(), f)),
"force toString to take parameters by ref");
})))
{
enum hasToString = HasToStringResult.customPutWriterFormatSpec;
}
else static if (is(typeof(
(T val) {
static struct S {void put(scope Char s){}}
static struct S
{
@disable this(this);
void put(scope Char s){}
}
S s;
val.toString(s);
static assert(!__traits(compiles, val.toString(S())),
"force toString to take parameters by ref");
})))
{
enum hasToString = HasToStringResult.customPutWriter;
@ -1996,9 +1998,10 @@ template hasToString(T, Char)
static assert(hasToString!(G, char) == customPutWriter);
static assert(hasToString!(H, char) == customPutWriterFormatSpec);
static assert(hasToString!(I, char) == customPutWriterFormatSpec);
static assert(hasToString!(J, char) == hasSomeToString);
static assert(hasToString!(J, char) == hasSomeToString
|| hasToString!(J, char) == constCharSinkFormatSpec); // depends on -preview=rvaluerefparam
static assert(hasToString!(K, char) == constCharSinkFormatSpec);
static assert(hasToString!(L, char) == none);
static assert(hasToString!(L, char) == customPutWriterFormatSpec);
static if (hasPreviewIn)
{
static assert(hasToString!(M, char) == inCharSinkFormatSpec);
@ -2105,9 +2108,10 @@ template hasToString(T, Char)
static assert(hasToString!(G, char) == customPutWriter);
static assert(hasToString!(H, char) == customPutWriterFormatSpec);
static assert(hasToString!(I, char) == customPutWriterFormatSpec);
static assert(hasToString!(J, char) == hasSomeToString);
static assert(hasToString!(J, char) == hasSomeToString
|| hasToString!(J, char) == constCharSinkFormatSpec); // depends on -preview=rvaluerefparam
static assert(hasToString!(K, char) == constCharSinkFormatSpec);
static assert(hasToString!(L, char) == none);
static assert(hasToString!(L, char) == HasToStringResult.customPutWriterFormatSpec);
static if (hasPreviewIn)
{
static assert(hasToString!(M, char) == inCharSinkFormatSpec);
@ -2125,9 +2129,10 @@ template hasToString(T, Char)
static assert(hasToString!(inout(G), char) == customPutWriter);
static assert(hasToString!(inout(H), char) == customPutWriterFormatSpec);
static assert(hasToString!(inout(I), char) == customPutWriterFormatSpec);
static assert(hasToString!(inout(J), char) == hasSomeToString);
static assert(hasToString!(inout(J), char) == hasSomeToString
|| hasToString!(inout(J), char) == constCharSinkFormatSpec); // depends on -preview=rvaluerefparam
static assert(hasToString!(inout(K), char) == constCharSinkFormatSpec);
static assert(hasToString!(inout(L), char) == none);
static assert(hasToString!(inout(L), char) == customPutWriterFormatSpec);
static if (hasPreviewIn)
{
static assert(hasToString!(inout(M), char) == inCharSinkFormatSpec);