www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - final switch problem

reply John Chapman <johnch_atms hotmail.com> writes:
If I use a final switch and import std.uni (or any other module 
that imports it, such as std.string), I'm getting unresolved 
external symbol errors with DMD 2.092.

This code triggers the issue:

---
module test;

import std.uni;

enum Cheese { cheddar, edam }

void test(Cheese cheese) {
   final switch (cheese) {
   case Cheese.cheddar: break;
   case Cheese.edam: break;
   }
}

void main() {
   test(Cheese.cheddar);
}
---

error LNK2019: unresolved external symbol "pure nothrow  nogc 
 safe void 
core.internal.switch_.__switch_error!().__switch_error(immutable(char)[],
ulong)" (_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv)
referenced in function _Dmain

If I remove "final" and add a default case, it compiles fine. Is 
this a bug or have I made a mistake? This worked a few days ago 
and I haven't changed my setup since then.
Jun 13 2020
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Sat, Jun 13, 2020 at 09:02:21AM +0000, John Chapman via Digitalmars-d-learn
wrote:
[...]
 module test;
 
 import std.uni;
 
 enum Cheese { cheddar, edam }
 
 void test(Cheese cheese) {
   final switch (cheese) {
   case Cheese.cheddar: break;
   case Cheese.edam: break;
   }
 }
 
 void main() {
   test(Cheese.cheddar);
 }
 ---
 
 error LNK2019: unresolved external symbol "pure nothrow  nogc  safe void
 core.internal.switch_.__switch_error!().__switch_error(immutable(char)[],
 ulong)" (_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv)
 referenced in function _Dmain
[...] Tested it on git master, DMD 2.091.1-beta.1 (Linux/64), could not reproduce problem.
From the error message, my first guess would be that your compiler and
druntime are out-of-sync somehow. T -- My father told me I wasn't at all afraid of hard work. I could lie down right next to it and go to sleep. -- Walter Bright
Jun 13 2020
prev sibling parent reply Boris Carvajal <boris2.9 gmail.com> writes:
On Saturday, 13 June 2020 at 09:02:21 UTC, John Chapman wrote:
 Is this a bug or have I made a mistake? This worked a few days 
 ago and I haven't changed my setup since then.
https://issues.dlang.org/show_bug.cgi?id=19548 Your code triggers it by using "-debug" option on https://run.dlang.io/ using DMD
Jun 13 2020
parent reply John Chapman <johnch_atms hotmail.com> writes:
On Saturday, 13 June 2020 at 15:33:55 UTC, Boris Carvajal wrote:
 On Saturday, 13 June 2020 at 09:02:21 UTC, John Chapman wrote:
 Is this a bug or have I made a mistake? This worked a few days 
 ago and I haven't changed my setup since then.
https://issues.dlang.org/show_bug.cgi?id=19548 Your code triggers it by using "-debug" option on https://run.dlang.io/ using DMD
Hmm, compiling with -release makes it work. Not a huge issue, I'll just avoid final switches in debug mode until it's fixed. Thanks.
Jun 13 2020
next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 6/13/20 9:22 AM, John Chapman wrote:

 Hmm, compiling with -release makes it work. Not a huge issue, I'll just 
 avoid final switches in debug mode until it's fixed. Thanks.
Apparently, it's a known issue: https://issues.dlang.org/show_bug.cgi?id=19548 Ali
Jun 13 2020
prev sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Saturday, June 13, 2020 10:22:39 AM MDT John Chapman via Digitalmars-d-
learn wrote:
 On Saturday, 13 June 2020 at 15:33:55 UTC, Boris Carvajal wrote:
 On Saturday, 13 June 2020 at 09:02:21 UTC, John Chapman wrote:
 Is this a bug or have I made a mistake? This worked a few days
 ago and I haven't changed my setup since then.
https://issues.dlang.org/show_bug.cgi?id=19548 Your code triggers it by using "-debug" option on https://run.dlang.io/ using DMD
Hmm, compiling with -release makes it work. Not a huge issue, I'll just avoid final switches in debug mode until it's fixed. Thanks.
Just be aware that that removes the code that gets generated which throws a SwitchError if the wrong value is passed to the final switch. So, instead of getting a SwitchError thrown, you'll get who-knows-what weird behavior happening if you have a bug with what you pass to the the switch (and of course, you lose assertions in general). It does sound like the problem that's resulting in the compilation error relates to the invisible default case that gets generated without -release though. - Jonathan M Davis
Jun 13 2020