Bug 21449 – PrimaryExp `TypeCtor( Type )( ArgumentList)` is rejected when used alone in a ExpStatement

Status
NEW
Severity
normal
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-12-03T09:10:00Z
Last change time
2024-12-13T19:13:12Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
basile-z
Moved to GitHub: dmd#19833 →

Comments

Comment #0 by b2.temp — 2020-12-03T09:10:00Z
using the ctor as an unary in an expstmt is an error (no effect) but for static opCall this can be valid. --- struct Foo { static opCall(T)(T t){} } void main() { Foo(0); //OK const(Foo(0)); //NG } --- >/tmp/temp_7F00CFE49E90.d:13:14: Error: unexpected `(` in declarator >/tmp/temp_7F00CFE49E90.d:13:15: Error: basic type expected, not `0` >/tmp/temp_7F00CFE49E90.d:13:15: Error: found `0` when expecting `)` >/tmp/temp_7F00CFE49E90.d:13:17: Error: no identifier for declarator `const Foo(_error_)` >/tmp/temp_7F00CFE49E90.d:13:17: Error: semicolon expected following function declaration >/tmp/temp_7F00CFE49E90.d:13:17: Error: found `)` instead of statement found by Herringway as seen on IRC.
Comment #1 by b2.temp — 2020-12-03T09:11:07Z
sorry, test case should be --- struct Foo { static opCall(T)(T t){} } void main() { Foo(0); //OK const(Foo)(0); //NG } ---
Comment #2 by b2.temp — 2021-09-28T16:17:45Z
in https://dlang.org/spec/expression.html#primary_expressions this is the rule TypeCtor ( Type ) ( ArgumentListopt ) The parser takes the path of a declaration, it nevers tries a statement, in this case ExpressionStatement.
Comment #3 by robert.schadek — 2024-12-13T19:13:12Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19833 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB