Код: Выделить всё
#include
#include
struct FunctorBase
{
typedef void (FunctorBase::*MethodPtr)();
template
Method get_method() const
{
return *static_cast(static_cast(_method));
}
FunctorBase(const void* method, std::size_t sz) : _method{}
{
std::memcpy(_method, method, sz);
}
alignas (MethodPtr) unsigned char _method[sizeof(MethodPtr)];
};
template
struct Functor1 : FunctorBase
{
typedef void (*Thunk)(const FunctorBase&, P1);
Functor1(Thunk t, const void* mf, size_t sz) : FunctorBase(mf, sz), thunk(t) {}
void operator()(P1 p1) const
{
thunk(*this, p1);
}
Thunk thunk;
};
template
struct MemberOf1stArgTranslator1 : Functor1
{
MemberOf1stArgTranslator1(const Method& m) : Functor1(thunk, &m, sizeof(Method)) {}
static void thunk(const FunctorBase& ftor, Callee callee)
{
(callee.*ftor.get_method())();
}
};
template
inline MemberOf1stArgTranslator1 create_functor(Functor1*, TRT (CallType::*const& f)())
{
typedef TRT (CallType::*Method)();
return MemberOf1stArgTranslator1(f);
}
struct MyCallee
{
void my_f() {}
};
void f()
{
typedef Functor1 F;
F f = create_functor((F*)0, &MyCallee::my_f);
MyCallee c;
f(c);
}
< /code>
Сообщаемое предупреждение: < /p>
In static member function 'static void MemberOf1stArgTranslator1::thunk(const FunctorBase&, Callee) [with Callee = MyCallee&; Method = void (MyCallee::*)()]',
inlined from 'void Functor1::operator()(P1) const [with P1 = MyCallee&]' at :31:7,
inlined from 'void f()' at :65:5:
:44:42: warning: array subscript 'int (**)(...)[0]' is partly outside array bounds of 'MyCallee [1]' [-Warray-bounds=]
44 | (callee.*ftor.get_method())();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
: In function 'void f()':
:64:13: note: object 'c' of size 1
64 | MyCallee c;
| ^
Что за компилятор пытается Расскажи мне здесь? Это реальная проблема с кодом или предупреждение ложным?
Подробнее здесь: https://stackoverflow.com/questions/794 ... om-g-legit
Мобильная версия