digitalmars.D - Static Analysis Tooling / Effective D
- Brian Schott (9/9) Jan 20 2014 I've checked in code to the DScanner project that gives it some
- Suliman (1/1) Jan 20 2014 It would be perfect have plugin for any Text Editor like Sublime
- Volcz (5/14) Jan 20 2014 I don't have any D specific errors that I keep repeating. I use
- Walter Bright (2/9) Jan 21 2014 Automated source code formatting would be nice (and it's not as easy as ...
- Dicebot (2/4) Jan 21 2014 It has nothing to do with static analysis.
- Walter Bright (3/7) Jan 21 2014 Coverity (a static analyzer) does checks based on whitespace indentation...
- Dicebot (6/8) Jan 21 2014 One can also say that it is not a huge leap for compiler to do
- bearophile (6/8) Jan 21 2014 This is good to have.
- Daniel Murphy (3/5) Jan 21 2014 That would be great, we could run it on the generated ddmd source and I
- Dicebot (10/19) Jan 21 2014 I'd personally love to see most of existing DMD warnings moved to
- Brian Schott (4/8) Jan 21 2014 I assume you're talking about something like @SuppressWarnings in
- Dicebot (6/14) Jan 21 2014 I was thinking of a more fine-tuned thing, similar to gcc
- Walter Bright (3/6) Jan 21 2014 Since we have user defined attributes, I don't see how anything further ...
- Dicebot (6/14) Jan 21 2014 See "reserved namespace" reference. It does not need any special
- Jacob Carlborg (8/12) Jan 21 2014 The answer to this is usually that each tool should use its own
- Walter Bright (5/9) Jan 21 2014 This is quite overengineering to put such in the spec.
- Brian Schott (6/18) Jan 21 2014 "test.d(10): Error: undefined identifier coverity_warnings"
- Walter Bright (5/14) Jan 21 2014 The trouble is if you start doing that, you end up in an endless ratrace...
- Jacob Carlborg (5/10) Jan 22 2014 Or just use an ugly string:
- Walter Bright (13/20) Jan 21 2014 Sooner or later, you're going to want to add data flow analysis. DFA wil...
- Jacob Carlborg (6/14) Jan 21 2014 Have a look at the Clang static analyzer as well. How accurate source
- Walter Bright (3/6) Jan 23 2014 Here's a great source of potential rules to add:
- Brian Schott (6/6) Apr 21 2014 I just added two new rules, a check for if/else blocks that are
- Kagamin (10/10) Apr 22 2014 Implicit conversion long - size_t - int.
- Kagamin (13/13) Apr 22 2014 Also escape analysis.
- Marco Leise (32/36) Apr 23 2014 Yes, this one:
- Steven Schveighoffer (5/18) Apr 23 2014 =AB.
- Marco Leise (7/30) Apr 23 2014 e:
- Steven Schveighoffer (9/36) Apr 24 2014 =
- Marco Leise (13/52) Apr 24 2014 e:
- Steven Schveighoffer (16/66) Apr 24 2014 =
- Artur Skawina via Digitalmars-d (14/20) Apr 24 2014 It does. That expression *always* yields an int [1]. Assigning the
- Marco Leise (9/12) Apr 24 2014 Am Thu, 24 Apr 2014 13:11:18 +0200
- Artur Skawina via Digitalmars-d (8/17) Apr 24 2014 Yes. D has not improved the situation in this area; it's no
I've checked in code to the DScanner project that gives it some basic static analysis capabilities. When run with the --styleCheck option, it will warn about a few things like empty declarations, implicit string concatenation, classes with lowercase_names, catching "Exception", and a few other things. There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?
Jan 20 2014
It would be perfect have plugin for any Text Editor like Sublime
Jan 20 2014
On Tuesday, 21 January 2014 at 04:34:57 UTC, Brian Schott wrote:I've checked in code to the DScanner project that gives it some basic static analysis capabilities. When run with the --styleCheck option, it will warn about a few things like empty declarations, implicit string concatenation, classes with lowercase_names, catching "Exception", and a few other things. There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?I don't have any D specific errors that I keep repeating. I use SonarQube at work with Java. Here is a list of some of the "rules" that I use: https://github.com/SonarSource/sonar-java/tree/master/java-checks/src/main/java/org/sonar/java/checks
Jan 20 2014
On 1/20/2014 8:34 PM, Brian Schott wrote:I've checked in code to the DScanner project that gives it some basic static analysis capabilities. When run with the --styleCheck option, it will warn about a few things like empty declarations, implicit string concatenation, classes with lowercase_names, catching "Exception", and a few other things. There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Automated source code formatting would be nice (and it's not as easy as it looks).
Jan 21 2014
On Tuesday, 21 January 2014 at 08:01:47 UTC, Walter Bright wrote:Automated source code formatting would be nice (and it's not as easy as it looks).It has nothing to do with static analysis.
Jan 21 2014
On 1/21/2014 12:54 AM, Dicebot wrote:On Tuesday, 21 January 2014 at 08:01:47 UTC, Walter Bright wrote:Coverity (a static analyzer) does checks based on whitespace indentation. It's not a great leap from there to just format it.Automated source code formatting would be nice (and it's not as easy as it looks).It has nothing to do with static analysis.
Jan 21 2014
On Tuesday, 21 January 2014 at 09:22:16 UTC, Walter Bright wrote:Coverity (a static analyzer) does checks based on whitespace indentation. It's not a great leap from there to just format it.One can also say that it is not a huge leap for compiler to do the same. Of course all those tool can share a lot of implementation and often are used together, but I think there is a value in keeping unrelated functionality separately available. UNIX-way ftw.
Jan 21 2014
Walter Bright:Coverity (a static analyzer) does checks based on whitespace indentation.This is good to have. Perhaps splitting the compiler in some parts could help people create such tools. Bye, bearophile
Jan 21 2014
"Walter Bright" wrote in message news:lbl9ha$i85$1 digitalmars.com...Automated source code formatting would be nice (and it's not as easy as it looks).That would be great, we could run it on the generated ddmd source and I wouldn't have to fix all the remaining formatting bugs!
Jan 21 2014
On Tuesday, 21 January 2014 at 04:34:57 UTC, Brian Schott wrote:I've checked in code to the DScanner project that gives it some basic static analysis capabilities. When run with the --styleCheck option, it will warn about a few things like empty declarations, implicit string concatenation, classes with lowercase_names, catching "Exception", and a few other things. There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?I'd personally love to see most of existing DMD warnings moved to DScanner and, after it get some recognition, removed from compiler completely. That, of course, implies some way to tune output for specific project, supressing some of detection patterns. That reminds me about related topic - do we have any pragma / attribute reserved for external tools? So that one could, for example, disable analysis error for specific part of sourc code without disabling it globally?
Jan 21 2014
On Tuesday, 21 January 2014 at 08:58:19 UTC, Dicebot wrote:That reminds me about related topic - do we have any pragma / attribute reserved for external tools? So that one could, for example, disable analysis error for specific part of sourc code without disabling it globally?I assume you're talking about something like SuppressWarnings in Java? http://docs.oracle.com/javase/7/docs/api/java/lang/SuppressWarnings.html
Jan 21 2014
On Tuesday, 21 January 2014 at 09:11:37 UTC, Brian Schott wrote:On Tuesday, 21 January 2014 at 08:58:19 UTC, Dicebot wrote:I was thinking of a more fine-tuned thing, similar to gcc `__attribute__ (unused)` but generalised a bit to not interfere with normal attributes by using reserved namespace. Single SuppressWarnings (analysis reports in our case) can be a simpler compromise though.That reminds me about related topic - do we have any pragma / attribute reserved for external tools? So that one could, for example, disable analysis error for specific part of sourc code without disabling it globally?I assume you're talking about something like SuppressWarnings in Java? http://docs.oracle.com/javase/7/docs/api/java/lang/SuppressWarnings.html
Jan 21 2014
On 1/21/2014 12:58 AM, Dicebot wrote:That reminds me about related topic - do we have any pragma / attribute reserved for external tools? So that one could, for example, disable analysis error for specific part of sourc code without disabling it globally?Since we have user defined attributes, I don't see how anything further needs to be added to the language.
Jan 21 2014
On Tuesday, 21 January 2014 at 09:30:45 UTC, Walter Bright wrote:On 1/21/2014 12:58 AM, Dicebot wrote:See "reserved namespace" reference. It does not need any special support from the language itself but some support from spec that will ensure that those attributes won't conflict with user code and other tools will be helpful. Probably even in form of guideline, not a rule.That reminds me about related topic - do we have any pragma / attribute reserved for external tools? So that one could, for example, disable analysis error for specific part of sourc code without disabling it globally?Since we have user defined attributes, I don't see how anything further needs to be added to the language.
Jan 21 2014
On 2014-01-21 10:33, Dicebot wrote:See "reserved namespace" reference. It does not need any special support from the language itself but some support from spec that will ensure that those attributes won't conflict with user code and other tools will be helpful. Probably even in form of guideline, not a rule.The answer to this is usually that each tool should use its own attributes and that fully qualified names should properly disambiguate the attributes. Although, in this case it might be asking a bit too much for a tool to be able to properly figure out fully qualified names of symbol names. -- /Jacob Carlborg
Jan 21 2014
On 1/21/2014 1:33 AM, Dicebot wrote:See "reserved namespace" reference. It does not need any special support from the language itself but some support from spec that will ensure that those attributes won't conflict with user code and other tools will be helpful. Probably even in form of guideline, not a rule.This is quite overengineering to put such in the spec. coverity_warnings should do fine (i.e. prefix with your tool name). It's not any harder than coming up with names for your third party library.
Jan 21 2014
On Tuesday, 21 January 2014 at 20:26:57 UTC, Walter Bright wrote:On 1/21/2014 1:33 AM, Dicebot wrote:"test.d(10): Error: undefined identifier coverity_warnings" In order for this to work the analysis tool would have to distribute a .d or .di file that is imported by any module that needs to suppress warnings. Java has the SuppressWarnings annotation in the standard java.lang to avoid this.See "reserved namespace" reference. It does not need any special support from the language itself but some support from spec that will ensure that those attributes won't conflict with user code and other tools will be helpful. Probably even in form of guideline, not a rule.This is quite overengineering to put such in the spec. coverity_warnings should do fine (i.e. prefix with your tool name). It's not any harder than coming up with names for your third party library.
Jan 21 2014
On 1/21/2014 1:07 PM, Brian Schott wrote:On Tuesday, 21 January 2014 at 20:26:57 UTC, Walter Bright wrote:The trouble is if you start doing that, you end up in an endless ratrace of adding ever more "standard" names. If you're going to use a static checker, it doesn't seem to me to be a big burden to provide an import for it.coverity_warnings should do fine (i.e. prefix with your tool name). It's not any harder than coming up with names for your third party library."test.d(10): Error: undefined identifier coverity_warnings" In order for this to work the analysis tool would have to distribute a .d or .di file that is imported by any module that needs to suppress warnings. Java has the SuppressWarnings annotation in the standard java.lang to avoid this.
Jan 21 2014
On 2014-01-21 22:07, Brian Schott wrote:"test.d(10): Error: undefined identifier coverity_warnings" In order for this to work the analysis tool would have to distribute a .d or .di file that is imported by any module that needs to suppress warnings. Java has the SuppressWarnings annotation in the standard java.lang to avoid this.Or just use an ugly string: ("coverity_warnings") -- /Jacob Carlborg
Jan 22 2014
On 1/20/2014 8:34 PM, Brian Schott wrote:I've checked in code to the DScanner project that gives it some basic static analysis capabilities. When run with the --styleCheck option, it will warn about a few things like empty declarations, implicit string concatenation, classes with lowercase_names, catching "Exception", and a few other things. There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Sooner or later, you're going to want to add data flow analysis. DFA will open up a universe of useful checks it can do. For example, you can do things like: class C { int x; } C foo() { return null; } int bar(int i) { auto c = i ? foo() : new C(); return c.x; // error, path to null dereference } and a heckuva lot more. For a laundry list, google Coverity and look at the bug reports it generates. Many of the reports have no meaning for D, as D has defined them out of existence, but there are plenty of others.
Jan 21 2014
On 2014-01-21 05:34, Brian Schott wrote:I've checked in code to the DScanner project that gives it some basic static analysis capabilities. When run with the --styleCheck option, it will warn about a few things like empty declarations, implicit string concatenation, classes with lowercase_names, catching "Exception", and a few other things. There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Have a look at the Clang static analyzer as well. How accurate source information is kept? Xcode can, with the help of Clang, graphically show the flow path. -- /Jacob Carlborg
Jan 21 2014
On 1/20/2014 8:34 PM, Brian Schott wrote:There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Here's a great source of potential rules to add: http://www.stroustrup.com/JSF-AV-rules.pdf
Jan 23 2014
I just added two new rules, a check for if/else blocks that are identical and a check for assign expressions where the left and right side of the '=' operator are the same. It found two bugs in Phobos: https://issues.dlang.org/show_bug.cgi?id=12609 https://issues.dlang.org/show_bug.cgi?id=12608
Apr 21 2014
Implicit conversion long - size_t - int. Null dereference can sometimes be detected statically, e.g. when the variable is not initialized. Possible null dereference after downcast, though this one can be annoying. I suggest to configure warnings with a config file, as the configuration can be big depending on the project code style. Another possibility is optional pragmas for really evil local overrides - resharper style comments - not only analysis tools can benefit from them.
Apr 22 2014
Also escape analysis. Bug found by frama-c: http://blog.frama-c.com/index.php?post/2014/02/23/CVE-2013-5914 Quote: "Allow me to put it this way: if the Apple SSL bug is a coup from the NSA, then you US citizens are lucky. Our spy agency in Europe is so much better that it does not even have a name you have heard before, and it is able to plant bugs where the buffer overflow leading to arbitrary code execution is three function calls away from the actual bug. The bug from our spy agency is so deniable that the code actually used to be fine when there were only two minor revisions of the SSL protocol. The backdoors from your spy agency are so lame that the Internet has opinions about them."
Apr 22 2014
Am Tue, 21 Jan 2014 04:34:56 +0000 schrieb "Brian Schott" <briancschott gmail.com>:There's a small feature wishlist in the project's README, but I'd=20 like to get some opinions from the newsgroup: What kinds of=20 errors have you seen in your code that you think a static=20 analysis tool could help with?Yes, this one: size_t shiftAmount =3D 63; [=E2=80=A6] auto x =3D 1 << shiftAmount; The trouble is that auto will now resolve to int instead of size_t as indicated by the type of shiftAmount. Sure, my fault was to use an innocent =C2=BB1=C2=AB instead of =C2=BBcast(size_t) 1=C2=AB.= So the result is: int x =3D -2147483648; But =C2=BB1 << size_t=C2=AB doesn't always yield an int result! Compare to this: size_t x =3D 1 << shiftAmount; which becomes: size_t x =3D 18446744071562067968; Two possible warnings could be: - Shifting an =C2=BBint=C2=AB by a =C2=BBsize_t=C2=AB is not the correct wa= y to enforce a =C2=BBsize_t=C2=AB result. Please use =C2=BBcast(size_t) 1 << shiftAmount=C2=AB if that was the intention. - =C2=BBauto=C2=AB variable definition will resolve to =C2=BBint=C2=AB and = may lose information from expression =C2=BB1 << shiftAmount=C2=AB. Please replace =C2=BBauto=C2=AB with =C2=BBint=C2=AB if that is what you want or= set the correct data type otherwise. In both cases an explicit mention of a data type resolves the ambiguity. --=20 Marco
Apr 23 2014
On Wed, 23 Apr 2014 22:56:54 -0400, Marco Leise <Marco.Leise gmx.de> wro= te:Am Tue, 21 Jan 2014 04:34:56 +0000 schrieb "Brian Schott" <briancschott gmail.com>:=AB. You could use 1UL instead. -SteveThere's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Yes, this one: size_t shiftAmount =3D 63; [=E2=80=A6] auto x =3D 1 << shiftAmount; The trouble is that auto will now resolve to int instead of size_t as indicated by the type of shiftAmount. Sure, my fault was to use an innocent =C2=BB1=C2=AB instead of =C2=BBcast(size_t) 1=C2=
Apr 23 2014
Am Wed, 23 Apr 2014 22:56:27 -0400 schrieb "Steven Schveighoffer" <schveiguy yahoo.com>:On Wed, 23 Apr 2014 22:56:54 -0400, Marco Leise <Marco.Leise gmx.de> wrot=e:=20=AB.Am Tue, 21 Jan 2014 04:34:56 +0000 schrieb "Brian Schott" <briancschott gmail.com>:There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Yes, this one: size_t shiftAmount =3D 63; [=E2=80=A6] auto x =3D 1 << shiftAmount; The trouble is that auto will now resolve to int instead of size_t as indicated by the type of shiftAmount. Sure, my fault was to use an innocent =C2=BB1=C2=AB instead of =C2=BBcast(size_t) 1=C2==20 You could use 1UL instead. =20 -SteveNo, that would give you a ulong result. --=20 Marco
Apr 23 2014
On Wed, 23 Apr 2014 23:15:01 -0400, Marco Leise <Marco.Leise gmx.de> wro= te:Am Wed, 23 Apr 2014 22:56:27 -0400 schrieb "Steven Schveighoffer" <schveiguy yahoo.com>:=On Wed, 23 Apr 2014 22:56:54 -0400, Marco Leise <Marco.Leise gmx.de> =1=C2=AB.wrote:Am Tue, 21 Jan 2014 04:34:56 +0000 schrieb "Brian Schott" <briancschott gmail.com>:There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Yes, this one: size_t shiftAmount =3D 63; [=E2=80=A6] auto x =3D 1 << shiftAmount; The trouble is that auto will now resolve to int instead of size_t as indicated by the type of shiftAmount. Sure, my fault was to use an innocent =C2=BB1=C2=AB instead of =C2=BBcast(size_t) =Hm... I was thinking in terms of 1 << 63, that must be a ulong, no? But I see your point that size_t may be 32 bits. I also think this will work: size_t(1); -SteveYou could use 1UL instead. -SteveNo, that would give you a ulong result.
Apr 24 2014
Am Thu, 24 Apr 2014 10:26:48 -0400 schrieb "Steven Schveighoffer" <schveiguy yahoo.com>:On Wed, 23 Apr 2014 23:15:01 -0400, Marco Leise <Marco.Leise gmx.de> wrot=e:=20=20Am Wed, 23 Apr 2014 22:56:27 -0400 schrieb "Steven Schveighoffer" <schveiguy yahoo.com>:On Wed, 23 Apr 2014 22:56:54 -0400, Marco Leise <Marco.Leise gmx.de> ==C2=AB.wrote:Am Tue, 21 Jan 2014 04:34:56 +0000 schrieb "Brian Schott" <briancschott gmail.com>:There's a small feature wishlist in the project's README, but I'd like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Yes, this one: size_t shiftAmount =3D 63; [=E2=80=A6] auto x =3D 1 << shiftAmount; The trouble is that auto will now resolve to int instead of size_t as indicated by the type of shiftAmount. Sure, my fault was to use an innocent =C2=BB1=C2=AB instead of =C2=BBcast(size_t) 1=Actually in _that_ case the compiler will yell at you that the valid range to shift an =C2=BBint=C2=AB is [0..31].=20 Hm... I was thinking in terms of 1 << 63, that must be a ulong, no?You could use 1UL instead. -SteveNo, that would give you a ulong result.But I see your point that size_t may be 32 bits. I also think this will work: =20 size_t(1); =20 -SteveBoth you and Artur mentioned it. Will this generalized ctor syntax be in 2.066 ? It looks much less like "code smell" when you don't have to use a cast any more even if it is just a rewrite. --=20 Marco
Apr 24 2014
On Thu, 24 Apr 2014 15:40:23 -0400, Marco Leise <Marco.Leise gmx.de> wro= te:Am Thu, 24 Apr 2014 10:26:48 -0400 schrieb "Steven Schveighoffer" <schveiguy yahoo.com>:=On Wed, 23 Apr 2014 23:15:01 -0400, Marco Leise <Marco.Leise gmx.de> =e>wrote:Am Wed, 23 Apr 2014 22:56:27 -0400 schrieb "Steven Schveighoffer" <schveiguy yahoo.com>:On Wed, 23 Apr 2014 22:56:54 -0400, Marco Leise <Marco.Leise gmx.d='dwrote:Am Tue, 21 Jan 2014 04:34:56 +0000 schrieb "Brian Schott" <briancschott gmail.com>:There's a small feature wishlist in the project's README, but I=t) 1=C2=AB.like to get some opinions from the newsgroup: What kinds of errors have you seen in your code that you think a static analysis tool could help with?Yes, this one: size_t shiftAmount =3D 63; [=E2=80=A6] auto x =3D 1 << shiftAmount; The trouble is that auto will now resolve to int instead of size_t as indicated by the type of shiftAmount. Sure, my fault was to use an innocent =C2=BB1=C2=AB instead of =C2=BBcast(size_=*sigh* The compiler is too smart for it's own good ;) This SHOULD compile and result in a long. I can't see how you would have= = meant anything else, and range propagation should work for a literal.Actually in _that_ case the compiler will yell at you that the valid range to shift an =C2=BBint=C2=AB is [0..31].Hm... I was thinking in terms of 1 << 63, that must be a ulong, no?You could use 1UL instead. -SteveNo, that would give you a ulong result.I don't know. I thought it was in 2.065, but see that it's not. I have = read that it was introduced somewhere, so I assumed it was already in. = Maybe only in git HEAD.But I see your point that size_t may be 32 bits. I also think this will work: size_t(1); -SteveBoth you and Artur mentioned it. Will this generalized ctor syntax be in 2.066 ?It looks much less like "code smell" when you don't have to use a cast any more even if it is just a rewrite.Yeah definitely. Cast should not be required for such mundane and = obviously safe things. -Steve
Apr 24 2014
On 04/24/14 04:56, Marco Leise via Digitalmars-d wrote:But »1 << size_t« doesn't always yield an int result! Compare toIt does. That expression *always* yields an int [1]. Assigning the result to a wider type does not affect the value (the overflow has already happened by then).size_t x = 1 << shiftAmount;This would almost certainly be a bug, if shiftAmount could ever become greater than 30. The `size_t = 1<<31` case is also very unlikely to do what the programmer intended.- »auto« variable definition will resolve to »int« and may lose information from expression »1 << shiftAmount«. Please replace »auto« with »int« if that is what you want or set the correct data type otherwise.`size_t x = 1 << shiftAmount` is definitely not something that should be recommended, see above. Just use the correct type on the lhs of shift operators. artur [1] there could be an exception for certain compile-time contexts, but I don't think that would work in D (same code would give different results when run at CT and RT).
Apr 24 2014
Am Thu, 24 Apr 2014 13:11:18 +0200 schrieb Artur Skawina via Digitalmars-d <digitalmars-d puremagic.com>:`size_t x = 1 << shiftAmount` is definitely not something that should be recommended, see above. Just use the correct type on the lhs of shift operators.auto x = cast(size_t) 1 << shiftAmount; // really ?! :( In that case it is better to define ONE as a constant :) enum ONE = cast(size_t) 1; auto x = ONE << shiftAmount; -- Marco
Apr 24 2014
On 04/24/14 14:49, Marco Leise via Digitalmars-d wrote:Am Thu, 24 Apr 2014 13:11:18 +0200 schrieb Artur Skawina via Digitalmars-d <digitalmars-d puremagic.com>:Yes. D has not improved the situation in this area; it's no different from C. A new enough compiler could make it look slightly better: auto x = size_t(1) << shiftAmount; Of course the more fundamental problem is that 'size_t' is just an alias and not a distinct type in D. artur`size_t x = 1 << shiftAmount` is definitely not something that should be recommended, see above. Just use the correct type on the lhs of shift operators.auto x = cast(size_t) 1 << shiftAmount; // really ?! :(
Apr 24 2014