D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7395 - Need error on declaring a variable after `if` and`synchronized` without {}
Summary: Need error on declaring a variable after `if` and`synchronized` without {}
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2012-01-29 04:13 UTC by Denis Shelomovskii
Modified: 2024-12-13 17:58 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2012-01-29 04:13:17 UTC
---
synchronized int i; // should be definitely an error

if(true) int i;     // IMHO, should be an error
if(true) l: f();    // should be probably an error
---

Consider the following D code copied from C:
---
volatile int* p; // volatile statements deprecated; use synchronized statements instead
---
A one is forced to change `volatile` -> `synchronized` after brief look at the error and, if he will be unhappy enough, his program will compile.

Therefore a case with `if` looks lass common but still signalize about an error.
An it is an error in C# (like a variant with label probably because of possible `l: int i;` case): `error CS1023: Embedded statement cannot be a declaration or labeled statement`.

Also look at Issue 2197.
Comment 1 dlangBugzillaToGithub 2024-12-13 17:58:12 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18409

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB