D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22053 - `catch {` not rejected while in a template
Summary: `catch {` not rejected while in a template
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, pull
Depends on:
Blocks:
 
Reported: 2021-06-20 21:27 UTC by Vladimir Panteleev
Modified: 2021-06-22 02:03 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 Vladimir Panteleev 2021-06-20 21:27:18 UTC
/////// test.d ///////
void foo()()
{
    try {}
    catch
        assert(false);
}

alias goo = foo!();
//////////////////////

This catch syntax (without specifying an exception) has been deprecated and is currently rejected when the code is not in a function template. However, the compiler does not reject it when it's inside a template, even when the template is instantiated.
Comment 1 Dlang Bot 2021-06-21 09:15:04 UTC
@Geod24 created dlang/dmd pull request #12721 "Fix 22053: Deprecate typeless catch at the parser level" fixing this issue:

- Fix 22053: Deprecate typeless catch at the parser level
  
  Type-less catch was previously deprecated only at the semantic level.
  This is usually good, because it avoids spurious deprecations being triggered
  in versioned-out code or generally unused (uninstantiated) code,
  or in code that is 'deprecated'.
  However, the syntax has been deprecated for years now, and should ultimately
  be removed from the parser, but while validating the grammar, it was found that
  the deprecation message didn't actually trigger in templated code, even instantiated.
  While we could fix it by triggering a deprecation only when the code is instantiated,
  this would still prevent us from removing support for parsing it.
  Instead, add a deprecation in the parser, so that code that wasn't caught before will be.
  The existing error is left in place, ensuring we don't regress.

https://github.com/dlang/dmd/pull/12721
Comment 2 Dlang Bot 2021-06-22 02:03:02 UTC
dlang/dmd pull request #12721 "Fix 22053: Deprecate typeless catch at the parser level" was merged into master:

- 85a12332f275a19b8e291489f3beb6e907310295 by Geod24:
  Fix 22053: Deprecate typeless catch at the parser level
  
  Type-less catch was previously deprecated only at the semantic level.
  This is usually good, because it avoids spurious deprecations being triggered
  in versioned-out code or generally unused (uninstantiated) code,
  or in code that is 'deprecated'.
  However, the syntax has been deprecated for years now, and should ultimately
  be removed from the parser, but while validating the grammar, it was found that
  the deprecation message didn't actually trigger in templated code, even instantiated.
  While we could fix it by triggering a deprecation only when the code is instantiated,
  this would still prevent us from removing support for parsing it.
  Instead, add a deprecation in the parser, so that code that wasn't caught before will be.
  The existing error is left in place, ensuring we don't regress.

https://github.com/dlang/dmd/pull/12721