Errors, bugs, questions - page 2682

 

MT5 bug (build 2367) Template functions execution priorities in MQL do not correspond to those in C++ (online: https://onlinegdb.com/B172m1PLL).
It seems that as part of the bug fix, the compilation bug is fixed, but the execution priority of overloaded template functions is still not aligned with C++ behavior.

template<typename T>
struct B{
   T data;
};

template<typename T>
struct BB : public B<T>{};


template<typename T>                                             
struct A{
public:
   static void test(T& src){
      printf("1");
   }
   
   template<typename TT>
   static void test(B<TT>& src){
      printf("2");
   }
};

                                         
struct AA{
public:
   static void test(B<int>& src){
      printf("1");
   }
   
   template<typename TT>
   static void test(B<TT>& src){
      printf("2");
   }
};
      

void OnStart(){
   BB<int> bb;
   
   A<B<int>>::test(bb);         // MQL:2,  should be 1     
   AA::test(bb);                // MQL:2,  should be 1     
}
 

I ran into a funny problem. It is impossible to pass a template type with several types-parameters into a macro, because the preprocessor does not know that it deals with a template and considers the parameters by commas.

I found the description of the problem and its solution for C++ in the SO.

#define  COMMA ,
#define  XYZ(type) {type ptr;}

XYZ(TemplatedType<A COMMA B>); // ошибка

I tried it in MQL, but unfortunately it didn't work. The compiler gives an error "undeclared identifier" for a variable described by the type passed.

So far I managed with an additional derived class, but may I correct it as in C++?

Oops. Found a solution. This is how it works:

#define  COMMA() ,
The question is removed.
Passing a template type into a macro
Passing a template type into a macro
  • 2017.05.30
  • bitmaskbitmask 22.3k1111 gold badges7070 silver badges133133 bronze badges
  • stackoverflow.com
I have a macro that takes a number of arguments, one of which is a type. For instance: If I try to instantiate this with a template type, say: This will not work as intended, as the pre-processor knows nothing of templates. It will...
 

MT5 bug (build 2367) location of overloaded template functions affects compilation result.
The original ticket under which the work was done -https://www.mql5.com/ru/forum/1111/page2655#comment_15119627
C++ online(https://onlinegdb.com/BJzbH2DLL).


class input_iterator_tag  {};
class forward_iterator_tag       : public input_iterator_tag         {};
class bidirectional_iterator_tag : public forward_iterator_tag       {};
class random_access_iterator_tag : public bidirectional_iterator_tag {};


template<typename _Iterator, typename _Tp>
_Iterator set_value(const _Iterator &it,  _Tp &value, const  forward_iterator_tag*  tag){
   printf("2\r\n");
   return set_value(it, value, (input_iterator_tag*)NULL);                // 'set_value' - ambiguous call to overloaded function        
};

template<typename _Iterator, typename _Tp>
_Iterator set_value(const _Iterator &it,  _Tp &value, const  bidirectional_iterator_tag*  tag){
   printf("3\r\n");
   return set_value(it, value, (forward_iterator_tag*)NULL);
};

template<typename _Iterator, typename _Tp>
_Iterator set_value(const _Iterator &it,  _Tp &value, const random_access_iterator_tag* tag){
   printf("4\r\n");
   return set_value(it, value, (bidirectional_iterator_tag*)NULL);
};

template<typename _Iterator, typename _Tp>
_Iterator set_value(const _Iterator &val,  _Tp &value, const input_iterator_tag* tag){
   printf("1\r\n");
   return val;
};


template<typename _Iterator, typename _Tp>
_Iterator set_value(const _Iterator &it, _Tp &value){
   return set_value(it, value, it.tag);                        
};


template<typename T>
struct A{
   T data;
   static random_access_iterator_tag* tag;
};

template<typename T>
random_access_iterator_tag* A::tag = NULL;

class B{};


void OnStart (){ 
   A<B*> it;
   const B* const b_ptr = new B();
   set_value(it, b_ptr);                                      
   
   A<int> it_int;
   const int value_int = 5;
   set_value(it, value_int);         
}

int main(){
   OnStart();
   return 0;
};
 

Defects in template function/class cache operation:
(fixed by MT5(build 2368)) ***(up) Undefined Behavior, you create a complex wrapped object with internal type "C" several times and it turns out to be a completely different data type, maybe "B", maybe "int", whatever you want...
(fixed by MT5(build 2368)) * Compile Error, bug on passing a function pointer as a const ref template argument.
(fixed by MT5(build 2368)) * Compile Error, the B<int> object may be created after the B<void*> object, but a compile error occurs if it is done before.


Defects in template function/class work:
(fixed by MT5(build 2368)) ***(up) Compile Error, bug inside template function, passed pointer withinexplicit type conversion behaves like a class otherwise.
(fixed by MT5(build 2368)) **(up) Compile Error, bug on attempting to access the internal class for a template parameter of a template function.
(not fixed by MT5(build 2368)) *** Compile Error, the main complaint is an inappropriate output warning - "deprecated behavior, hidden method calling will be disabled in a future MQL compiler version". The current implementation is shooting birds with a feather.
(not fixed by MT5(build 2368)) ** Compile Error, the bug concerns the return value of a template function when the return value is an internal class inside a template class whose parameter type is set by the argument type of the template function.
(not fixed by MT5(build 2368)) ** Compile Error, namespace and scope bug in the template constructor when calling a base class when the same class name is used in inheritance and in the internal class.
(not fixed by MT5(build 2368)) * Compile Error, bug on template function call with explicit argument types when called from overloaded non-template function.
(not fixed by MT5(build 2368)) Compile Error, bug on internal class definition - no reference to global namespace when defining a base class.
(fixed by MT5(build 2368)) ** Compile Error, bug with template class code generation when using internal class.
(fixed by MT5(build 2368)) ** Compile Error, bug on template method/class generation, the process of template parameter's auto substitution goes out of the scop into the main program code.
(fixed by MT5(build 2368)) * Compile Error, bug with not generating template class code automatically when template class acts as return value for the template method.
(fixed by MT5(build 2368)) * Compile Error, bug in passing internal struct to template function, the resultingdata type cannot be used as the base data type for another internal struct in the template class.
(fixed by MT5(build 2368)) * Compile Error, the check for reused template type names is not performed when declaring a template function inside a template class, which leads to unexpected behavior.
(fixed by MT5(build 2368)) Compile Error, multiple defects related to return "in place created" object when the object is a template class/structure.
(not fixed by MT5(build 2368)) *( It's not a bug, it's a feature) in base class constructor it is impossible to perform explicit typecast on converting pointer to object of base class to pointer to parent class.


Defects related to inconsistency in priorities of calls of overloaded functions in MQL vs C++:
(fixed by MT5(build 2368)) **(up) Compile Error, call priority of overloaded template functions actually depends on template parameter type, which theoretically does not affect compilation result.
(fixed by MT5(build 2368)) **(up) Compile Error when the first overloaded template function uses a fully specialized template base class and the second uses a nonspecialized template base class.
(not fixed by MT5(build 2368)) ** Compile Error, a compile error occurs while generating code for a template function despite the fact that there is an overloaded template function with a suitable signature for the passed parameters.
(not fixed by MT5(build 2368)) * Compile Error, "ambiguous call to overloaded function" when overloaded template functions with different number of template parameters are called.
(fixed by MT5(build 2368)) *** Compile Error when inheriting classes A <= B <= C <= D and implementing two overloading functions, for example, one with parameter A* and second with parameter B*, then passing an object C* or D* in such function in MQL causes a compilation error "ambiguous call to overloaded function".
(fixed by MT5(build 2368)) ** Runtime, Priority mismatch for calls of overloaded template functions.

Defects related to slow function execution, code optimizer performance:
(fixed by MT5(build 2368)) ** Runtime, large overhead when adding one element at a time into an array using ArrayResize, despite the fact that the memory for them has been reserved, for example, structures are up to 7 times slower.


Suggestions:
(new) link - about implementing intellisense support for namespace functionality based on intellisense work for static methods in classes.
link- to allow literals and temporary variables to be passed as const ref function arguments.
link- whenmoving projectfiles in the Project tab, for moved files that are open and in ME tabs, to automatically update their location path.
link- to introduce typedef declaration functionality in MQL.
link- about providing possibility to force generation of default copy constructors and assignment operators.

 
MT5 bug (build 2368) compilation error when using default access modifier when inheriting in template class, when template parameter acts as base class.
Everything worked before, apparently something broke as part of fixing other bugs.

class A{};

template<typename T>
class B : T{};            //'A' - unexpected token      

template<typename T>
class BB : private T{};

   
void OnStart(){    
   BB<A> bb;      // Ok
   B<A> b;        // Compile Error: 
}
 

MT5 bug (build 2368) compilation error when calling assignment statement via explicit base class indication. The problem occurs fora template class with template parameter as base class.
It worked before, apparently something broke as part of fixing other bugs.

struct A{
   uchar data;
   void operator=(int n){
      printf("1");
   }
};

template<typename T>
struct B : public T{
   void operator=(int n){
      T::operator=(n);    //'operator' - undeclared identifier  
   }
};

   
void OnStart(){    
   B<A> b;        
   b = 0;
}
 
Has everyone's MT5 update from 08.03.2020 started to have a jumping trade history?
Files:
 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2020.03.22 10:04

mq5 is ok. mq4 is broken. You can take TypeToBytes_ExampleScript.mq4 from here. It compiles only if you change the extension to mq5.

2368 - nothing has changed.

 

Through one MT5 terminal I could always log in to any broker's account. If there was a problem with the first login, I simply used the Terminal's tools to search for the appropriate broker, automatically obtaining the data of its trading servers. After that I could login without any problems.


Today I have faced with a situation for the first time (new broker), that nothing helps. I cannot log in. In log writes.

2020.03.25 09:50:33.538  'xxx': no connection to XXX-Server


I have downloaded the broker's native terminal - logs in immediately. My research terminal - no way. For the first time such.

Can you tell me how to make a non-native terminal be able to connect to the trading account?

 
fxsaber:

Can you tell me how to make a non-native terminal be able to connect to a trading account?

In mt4 I had to copy server.ini file to another terminal, so I wouldn't have to search for trade servers

do not know in mt5