Questions tagged [compiler-generated]

22 questions
27
votes
2 answers

Implicit conversion to System.Double with a nullable struct via compiler generated locals: why is this failing?

Given the following, why does the InvalidCastException get thrown? I can't see why it should be outside of a bug (this is in x86; x64 crashes with a 0xC0000005 in clrjit.dll). class Program { static void Main(string[] args) { …
codekaizen
  • 26,990
  • 7
  • 84
  • 140
18
votes
2 answers

Understanding compiler-generated type in dotPeek decompiled code

Hei. I was reading Digi Traffic Accelerator's decompiled source (I think it is the best way to learn), until I got some non-understandable code! Please take a look: internal class ProxyFarm { private static Random rand = new Random(); …
amiry jd
  • 27,021
  • 30
  • 116
  • 215
11
votes
1 answer

Why does a bool "flag" get generated for the async/await state machine?

If you compile the following code: private async Task M() { return await Task.FromResult(0); } And then decompile it (I used dotPeek) and examine the all-important MoveNext method, you will see a bool variable declared near the beginning;…
Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
9
votes
2 answers

Does this code result in a materialized base prvalue, and should it compile?

The following code compiles in gcc 9.1 godbolt but not clang 8 godbolt: class A { protected: ~A() = default; }; class B final : public A { }; int main() { auto b = B{}; } Clang's error: :10:16: error: temporary of type 'A' has…
Jeff Garrett
  • 5,863
  • 1
  • 13
  • 12
8
votes
4 answers

Are any C++ operator overloads provided automatically based on others?

Say I'm writing an int wrapper and need to provide every single operator overload. Must the author list out every single one, or can it auto-generate any based on what the author has provided? Can/does the compiler infer any new auto-defined…
VoidStar
  • 5,241
  • 1
  • 31
  • 45
8
votes
7 answers

Will the compiler-generated default constructor be public?

When I write a class Widget.java public class Widget { int data; String name; } will the compiler-generated constructor be public or default? public would be like public class Widget { int data; String name; public Widget()…
towi
  • 21,587
  • 28
  • 106
  • 187
6
votes
4 answers

Will the compiler-generated destructor of an abstract base class be virtual?

class Base { virtual void foo() = 0; //~Base(); <-- No destructor! }; Obviously, Base will be derived. So, does C++ says the compiler-generated destructor of Base must be virtual? Thanks!
Julien-L
  • 5,267
  • 3
  • 34
  • 51
4
votes
1 answer

C# async/await efficiency (or abusing) on reading DbDataReader

Stumbled upon a relatively often used piece of code which seemed inefficient at first. (I know optimization could be evil sometimes, but I was wondering) introduction part - fairly simple SP execution + reading the returned data: try { await…
noobed
  • 1,329
  • 11
  • 24
4
votes
1 answer

Destructor protection in abstract base class is not inherited in C++?

I found a memory leak in my code that was caused by calling only the base class destructor for objects. This problem is understood: I already added the virtual to the destructor of the interface class MyÌnterface. What puzzles me is that the…
Wolf
  • 9,679
  • 7
  • 62
  • 108
3
votes
2 answers

How to generate a look-up table in compile time in C++?

I have been attempting to implement a compiler generated look-up table containing the values of the sine function. The C++ code looks like this #include #include #include #include using namespace…
Steve
  • 805
  • 7
  • 27
3
votes
0 answers

.NET 5 Source Generators. How use also referenced assembly

I try to use .NET 5 Source Generators for generate webapi controllers starting from commands and queries. I use this article [example]https://www.edument.se/en/blog/post/net-5-source-generators-mediatr-cqrs for this But i want use commands and…
3
votes
1 answer

For `case class Cc(a: Int, b: Int) extends MyTraitA`, where does `MyTraitA` appear with `Product` and `Serializable` traits?

Because of inheritance linearization in Scala, I would like to understand how traits I specify for a case class are ordered relative to the two traits automatically generated and added by the Scala compiler; i.e. Product with Serializable (and…
3
votes
1 answer

Does compiler generated copy constructor/assignment renders it's parameter with const/volatile

There are some functions which compiler could implicitly define for us in case of need and if they can be properly defined for that class. Like default constructor copy constructor assignment operator destructor. So, whether compiler generated…
ravi
  • 10,994
  • 1
  • 18
  • 36
2
votes
0 answers

Detect whether C#-method uses yield return

I am trying to write a simple caching mechanism. Basically, whenever a method is called, its return value should be saved in a cache. Using AOP, my simplified CacheAspect looks as follows. using Castle.DynamicProxy; public class CacheAspect :…
2
votes
1 answer

Why is there a `null` check in the implementation of the `unapply` method for case classes?

I'm working to replace the unapply method on a case class's companion object with my own implementation. And after investigating lots of different tangents related to implementing unapply, it appears there is a null guard in most of them, both in…
1
2