D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4908 - Compile-time use of empty() in Tuple failed depending on order of compilation
Summary: Compile-time use of empty() in Tuple failed depending on order of compilation
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL: http://svn.dsource.org/projects/phobo...
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2010-09-21 12:25 UTC by Shin Fujishiro
Modified: 2015-11-01 01:50 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010-09-21 12:25:25 UTC
I have no reduced test case yet.

Unzip the dmd 2.049 release. Add the following lines to std/typecons.d:
--------------------
  struct Tuple(T...)
  {
+     static string test()
+     {
+         enum s = "";
+         return s.empty ? ";" : ";";   // (316)
+     }
+     mixin(test());                    // (318)
  public:
--------------------

Then, compiling certain modules fails depending on the order of compilation:
--------------------
% dmd -c std/string std/concurrency
std/typecons.d(316): Error: cannot evaluate empty("") at compile time
std/typecons.d(318): Error: cannot evaluate test() at compile time
std/typecons.d(318): Error: argument to mixin must be a string, not (test())
% dmd -c std/concurrency std/string
% _
--------------------

The error didn't occur if I modified std.string.indexOf() as follows:
--------------------
  sizediff_t
  indexOf(Char1, Char2)(in Char1[] s, in Char2[] sub,
          CaseSensitive cs = CaseSensitive.yes)
  {
      if (cs == CaseSensitive.yes)
      {
          static if (Char1.sizeof == Char2.sizeof)
          {
-             immutable result = s.length - std.algorithm.find(s, sub).length;
+             immutable result = 0;
              return result == s.length ? -1 : result;
--------------------

This bug is no longer triggered in phobos since changeset 2032.
 http://svn.dsource.org/projects/phobos/trunk@2032
Comment 1 Infiltrator 2015-11-01 01:50:03 UTC
Since the bug is no longer triggered since an old SVN commit, I think that we can consider this resolved.