D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10329 - Attributes not inferred for indirectly templated methods
Summary: Attributes not inferred for indirectly templated methods
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 blocker
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
: 10878 11556 11866 (view as issue list)
Depends on:
Blocks:
 
Reported: 2013-06-10 23:04 UTC by Lars T. Kyllingstad
Modified: 2014-01-05 16:34 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lars T. Kyllingstad 2013-06-10 23:04:32 UTC
Currently, attributes such as @safe, pure and nothrow are automatically inferred for function templates.  They should also be inferred for methods of struct/class templates and for Voldemort types.

Test case:

  struct S1
  {
      void foo(T)() { }
  }

  struct S2(T)
  {
      void foo() { }
  }

  auto makeS3(T)()
  {
      struct S3
      {
          void foo() { }
      }
      return S3();
  }

  void main() @safe pure nothrow
  {
      // Works
      S1 s1;
      s1.foo!int();

      // Compilation failure
      S2!int s2;
      s2.foo();

      // Compilation failure
      auto s3 = makeS3!int();
      s3.foo();
  }

This currently prevents large parts of Phobos from being used in @safe/pure/nothrow contexts, and it prevents parts of Phobos from being marked as such.  It also blocks some changes to std.path that I have in the pipeline, because I want to reimplement a function in terms of std.algorithm functions without removing its current attributes (as this would be a breaking change).

A workaround (which is *not* feasible for use in Phobos) is to make the methods themselves trivial templates:

  struct S2(T)
  {
      void foo()() { }
  }
Comment 1 Andrej Mitrovic 2013-06-11 07:25:06 UTC
Yeah, I think Kenji also mentioned he'd like to see this implemented.
Comment 2 Lars T. Kyllingstad 2013-06-14 12:27:31 UTC
Attributes should also be inferred for functions nested in function templates:

  void foo(T)()
  {
      void inner() { }
      inner();
  }

  void main() @safe pure nothrow
  {
      // Compilation failure:
      foo!int();
  }
Comment 4 monarchdodra 2013-08-24 10:24:04 UTC
*** Issue 10878 has been marked as a duplicate of this issue. ***
Comment 5 hsteoh 2013-10-16 14:32:21 UTC
This bug makes std.range.chain unusable in pure code.
Comment 7 monarchdodra 2013-11-19 23:09:08 UTC
*** Issue 11556 has been marked as a duplicate of this issue. ***
Comment 8 Kenji Hara 2014-01-05 00:43:42 UTC
*** Issue 11866 has been marked as a duplicate of this issue. ***
Comment 9 github-bugzilla 2014-01-05 15:35:56 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/237bb420c70fb6099dcedf94e7d9ed959a33e1fe
fix Issue 10329 - Attributes not inferred for indirectly templated methods

https://github.com/D-Programming-Language/dmd/commit/ebae884d9cd3a0c4ebf3c1b129654ba31ee0e73f
Merge pull request #2832 from 9rnsr/fix10329

Issue 10329 - Attributes not inferred for indirectly templated methods