Errors, bugs, questions - page 2663

 
You have a serious bug in the calculation of the stock markets and you do not care, and it is unclear whether the problem goes unnoticed purposefully or accidentally
 
Aleksey Vyazmikin:

I have a tough case - there is no logic available to me.

There is a function with these inputs

So, this Function sometimes outputs a value of 769

If you uncomment the first print

then it gives the correct value.

If you truncate the function by removing just the code which is not activated at the moment the function is called at the moment of error, there is no error either.

Obviously a compiler error - developers, who should I send the full function to, it doesn't fit on the forum.

I did it through switch - everything works. It must be the compiler, then.

 
Unable to commit to a storage...
 
Alexey Kozitsyn:
Unable to commit to a storage...

It's already working, I think.

 
Artyom Trishkin:

It's already working, I think.

Yes.

 
MT5 bug (build 2345), another manifestation of the previously described bug, where a pointer passed to a template function acts as a data type pointer for some operations and as a data type class for others:

#define  PRINT(x) ; Print(#x, ":", string(x))

template<typename T>
T test(T ptr){
   PRINT(typename(ptr));   // A*
   PRINT(typename(T));     // A*
   
   T new_ptr = new T();
   return (new_ptr);
}


class A{};
   
void OnStart(){    
   A a;
   test(&a);                   // Compile Error: OK
}
 

Bug MT5 (build 2345), no check for reused template type names when declaring a template function inside a template class, leading to unexpected behaviour:

#define  PRINT(x) ; Print(#x, ":", string(x))

template<typename T>
class A{
public:   
   template<typename T>         // Compile Error: OK
   T test(T p){
      B b = NULL;
      PRINT(typename(B));       // C*
      PRINT(typename(b));       // C*
      return b;
   }
   
   //real template
   template<typename TT>
   TT test_real(TT p){
      TT b = NULL;
      PRINT(typename(TT));       
      PRINT(typename(b));        
      return b;
   }
};

class B{};
class C : public B{};

   
void OnStart(){  
   A<B> a; 
   B b;
   C c;
    
   C* c_ptr = a.test(&c);
}
 
Bug MT5 (build 2345) lacks encapsulation when working with template class methods:

class B{
private:
   template<typename T>
   void you_cannot_call_private_method(T n){
      printf("Wow, Nice job.");
   }
};
   
void OnStart(){  
   B b;   
   b.you_cannot_call_private_method(1);          // Wow, Nice job.
}
 
MT5 bug (build 2345) in the base class constructor, you cannot perform an explicit typecast to cast a pointer to an object of a base class to a pointer to a parent class.

#define  PRINT(x) ; Print(#x, ":", string(x))

template<typename T>
class A{
   T* virtual_call;
   
public:   
   A(T* ptr){
      virtual_call = dynamic_cast<T*>(&this);
      PRINT(virtual_call == NULL);              // true, virtual_call == NULL
      
      virtual_call = dynamic_cast<T*>(ptr);
      PRINT(virtual_call == NULL);              // false, virtual_call != NULL
      
      virtual_call = (T*)(&this);               // Execution Error: Incorrect casting of pointers.
      virtual_call = (T*)(ptr);                 // OK
   } 
      
   template<typename TT>
   void test(TT n){
      virtual_call.__test(n);
   }
   
   template<typename TT>
   void __test(TT n){
      printf("AAAA");
   }
};


class B : public A<B>{
public:
   B() : A(&this){}

   template<typename TT>
   void __test(TT n){
      printf("BBBB");
   }
};
   
class C : public A<C>{
public:
   C() : A(&this){}
};

   
void OnStart(){  
   B b;   
   b.test(1);        // should be "BBBB"
   
   C c;
   c.test(1);        // should be "AAAA"
}

It turns out that to implement "pattern" emulation of virtual template functions it is necessary to pull the direct value of the pointer to the parent class into the base class besides the type inheritance, which is not good...
 

Does anyone have this compiled?

class B {};

template<typename T>
class A
{
    static T *array;
    
    static void check()
    {
      T *ptr = array; // unresolved static variable 'A<B>::array'
    }
};

class Y: public A<B>
{
};

template<typename T>
static T *A::array;

void OnStart()
{
  Y y;
}

What's wrong with it?

Reason: