Comments (15)
Yes, I would totally vote for this being a false positive, as it's parametrized for the number of elements (return + this + arguments). I bet the analyzer gets confused by the typelist element counter.
from luabind-deboostified.
I think I have found a way for a workaround to avoid any similar things and keep logic work:
https://stackoverflow.com/questions/11363822/compile-time-conditional-member-function-call-in-c
I'll try something at me, and if will success, I'll pull that to you.
from luabind-deboostified.
Great, I'll stay tuned.
Btw, I'm amazed how well the cmake integration works with Visual Studio nowadays! ;)
from luabind-deboostified.
Something I did, wasn't tested yet that:
template <size_t S>
typename std::enable_if<S != 1>::type increase_if_sz_is_not_1(size_t &)
{
//Do nothing!
}
template <size_t S>
typename std::enable_if<S == 1>::type increase_if_sz_is_not_1(size_t &ncat)
{
++ncat;
}
template <class Signature>
void format_signature(lua_State* L, char const* function, Signature)
{
using first = typename meta::front<Signature>::type;
type_to_string<first>::get(L);
lua_pushstring(L, " ");
lua_pushstring(L, function);
lua_pushstring(L, "(");
format_signature_aux(
L
, true
, typename meta::pop_front<Signature>::type()
);
lua_pushstring(L, ")");
const size_t sz = meta::size<Signature>::value;
size_t ncat = sz * 2 + 2;
increase_if_sz_is_not_1<sz>(ncat);
lua_concat(L, ncat);
}
from luabind-deboostified.
Hrmm, I feel uneasy adding enable_if tricks for a static analysis. Maybe removing "sz" in favor for duplicate calls to meta::size::value would do the trick already?
from luabind-deboostified.
The thing is: that meta::size::value is represents as const value which doesn't changes, and logical condition that never uses second way is dead.
Anyway, trick number two:
template <size_t S>
typename std::enable_if<S != 1>::type get_ncat()
{
return S * 2 + 2;
}
template <size_t S>
typename std::enable_if<S == 1>::type get_ncat()
{
return S * 2 + 2 + 1;
}
template <class Signature>
void format_signature(lua_State* L, char const* function, Signature)
{
using first = typename meta::front<Signature>::type;
type_to_string<first>::get(L);
lua_pushstring(L, " ");
lua_pushstring(L, function);
lua_pushstring(L, "(");
format_signature_aux(
L
, true
, typename meta::pop_front<Signature>::type()
);
lua_pushstring(L, ")");
//const size_t sz = meta::size<Signature>::value;
//size_t ncat = sz * 2 + 2;
size_t ncat = get_ncat<meta::size<Signature>::value>();
lua_concat(L, static_cast<int>(ncat));
}
P.S. Seems here I did some mistake to use std::enable_if, and I'll fix that
from luabind-deboostified.
What about something like
ncat + std::conditional_t<meta::size<Signature>::value == 1, std::integral_constant<int, 1>, std::integral_constant<int, 0>>::value
which would maybe make special code unnecessary?
from luabind-deboostified.
Oh, I totally forgot about constexpr
thing:
lua_pushstring(L, ")");
//const size_t sz = meta::size<Signature>::value;
//size_t ncat = sz * 2 + 2;
constexpr size_t ncat = meta::size<Signature>::value * 2 + 2 +
(meta::size<Signature>::value == 1 ? 1 : 0);
lua_concat(L, static_cast<int>(ncat));
So, because the meta::size::value is constant based on input type, I have to use constexpr that will be processed in compile time
What about something like
ncat + std::conditional_tmeta::size<Signature::value == 1, std::integral_constant<int, 1>, std::integral_constant<int, 0>>::value
which would maybe make special code unnecessary?
I think, also may be usedful, need to also check out that
from luabind-deboostified.
Right, does Coverity understand constexpr? Since there's still a hidden if/else there in my understanding.
from luabind-deboostified.
Yes, since it supports C++11 and constexpr is C++11 feature, at my build machine on Travis CI it builds with GCC 6.3. I'll try to push that to my side and if Converity Scan will confirm fixing of that, I'll send change to you
from luabind-deboostified.
I don't know the inner workings of Coverity and how it relates to GCC.
If the constexpr/ternary solution works, then so much better. Though that breaks the backwards compatibility to msvc 2013 I suppose... would anyone still care?
from luabind-deboostified.
MSVC 2013 is usually still be used in companies who are too lazy to do various updates. MSVC 2013 lacks lots of things are already existing in CLang and GCC, and code that compatible with MSVC 2013 must be C++98, and are rare features of C++11 are existing.
My opinion: MSVC 2015 is the first version which is much more friendly with modern code. I have used the constexpr
because I have already found two usages of it in the inheritance.cpp
file (and a two another usages I have added to fix "undefined reference" linking failing).
Components of my game engine project are not compatible with MSVCs because of wide C++11/14 code usage, and on Windows, I have used MinGW and MinGW-w64. One small exception is come when I did to be compatible some parts of it (some libraries, and music player), but with MSVC 2015 and higher only.
from luabind-deboostified.
Well, then I'd probably bump to 2015 requirement and revert to using a std::conditional construct, if somebody objects?
I'm running the community edition for this private stuff, so I was always on the "latest" version since its existance.
from luabind-deboostified.
Okay, Coverity Scan has been confirmed fix:
I'll prepare pull request
from luabind-deboostified.
Fixed!
from luabind-deboostified.
Related Issues (20)
- const references to floats do not work with object calls HOT 5
- runtime error when calling lua function from C++, passing a const char* HOT 6
- Returning a null smart pointer from C++ does not return a nil object HOT 9
- assertion failure in object_rep::add_dependency HOT 6
- Do you have any plans to extend initial functionality? HOT 2
- gcc Error: wrong number of template arguments (1, should be 3) HOT 13
- Support object_cast_nothrow with std::optional HOT 3
- Unit test "test_policies.cpp" fails to be build on GCC 6.3 because of "out_value_policy.hpp" HOT 1
- test_implicit_cast.cpp test fails
- Lua classes from C++ HOT 33
- Terminate only when callback wasn't set HOT 4
- Which branch does not contain the boost dependency? HOT 1
- Calling C++ functions with default arguments from Lua HOT 8
- Multiple Return Values HOT 2
- Failed to build latest state (87897cf) on GCC 6.4.0 HOT 4
- set_package_preload?
- test_implicit_cast crashes gcc 4.7.3 HOT 2
- pure_out_value with discard_result HOT 3
- warning: class template partial specialization contains template parameters that can not be deduced; this partial specialization will never be used
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luabind-deboostified.