D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20507 - Debug statements affect inference of templated functions attributes
Summary: Debug statements affect inference of templated functions attributes
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-01-15 15:32 UTC by moonlightsentinel
Modified: 2020-01-16 00:49 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 moonlightsentinel 2020-01-15 15:32:46 UTC
debug statements are allowed to violate @safe, pure, @nogc and nothrow (allthough the latter is not implemented right now). But they influence the attribute interference:

----------------------------------------------

void main() pure /* nothrow */ @safe @nogc
{
    debug foo();
    bar!()();
}

void foo() @system
{
    // Just to be sure its neither @nogc, pure or nothrow
    __gshared int counter = 0;

    if (counter++)
        throw new Exception(new immutable(char)[counter]);
}

void bar()()
{
    debug foo();
}

----------------------------------------------

..\debugging.d(4): Error: @safe function D main cannot call @system function debugging.bar!().bar
..\debugging.d(16):        debugging.bar!().bar is declared here
..\debugging.d(4): Error: @nogc function D main cannot call non-@nogc function debugging.bar!().bar

----------------------------------------------

The debug statement caused bar to become @system, non-@nogc and non-nothrow.
Comment 1 Dlang Bot 2020-01-15 15:38:28 UTC
@MoonlightSentinel created dlang/dmd pull request #10726 "Fix Issue 20507 - Debug statements affect inference..." fixing this issue:

- Fix Issue 20507 - Debug statements affect inference...
  
  ...of templated functions attributes.
  
  This was caused by marking the function as @system/non-@nogc/non-nothrow BEFORE
  checking whether the statement is inside an debug statement / block

https://github.com/dlang/dmd/pull/10726
Comment 2 Dlang Bot 2020-01-16 00:49:37 UTC
dlang/dmd pull request #10726 "Fix Issue 20507 - Debug statements affect inference..." was merged into master:

- a7750e0a949f5f3183aecd5a3c9943e19078f6f6 by MoonlightSentinel:
  Fix Issue 20507 - Debug statements affect inference...
  
  ...of templated functions attributes.
  
  This was caused by marking the function as @system/non-@nogc/non-nothrow BEFORE
  checking whether the statement is inside an debug statement / block

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