Skip to content

Commit

Permalink
Merge pull request #236 from eranpeer/fix_msvc_warnings_from_gcc_stuff
Browse files Browse the repository at this point in the history
Fix MSVC warnings from GCC pragma / attributes
  • Loading branch information
FranckRJ committed Apr 10, 2021
2 parents 4716aca + f2e43f2 commit 74ff9ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/mockutils/VTUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ namespace fakeit {
class VTUtils {
public:

#ifdef __GNUG__
#ifndef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
#endif
template<typename C, typename R, typename ... arglist>
static unsigned int getOffset(R (C::*vMethod)(arglist...)) {
auto sMethod = reinterpret_cast<unsigned int (VirtualOffsetSelector::*)(int)>(vMethod);
VirtualOffsetSelector offsetSelctor;
return (offsetSelctor.*sMethod)(0);
}
#ifdef __GNUG__
#ifndef __clang__
#pragma GCC diagnostic pop
#endif
#endif

template<typename C>
static typename std::enable_if<std::has_virtual_destructor<C>::value, unsigned int>::type
Expand Down
9 changes: 8 additions & 1 deletion include/mockutils/union_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
* Created on Mar 10, 2014
*/
#pragma once

#if defined(__GNUG__) && !defined(__clang__)
#define FAKEIT_NO_DEVIRTUALIZE_ATTR [[gnu::optimize("no-devirtualize")]]
#else
#define FAKEIT_NO_DEVIRTUALIZE_ATTR
#endif

namespace fakeit {

template<typename TARGET, typename SOURCE>
[[gnu::optimize("no-devirtualize")]]
FAKEIT_NO_DEVIRTUALIZE_ATTR
TARGET union_cast(SOURCE source) {
//static_assert(sizeof(TARGET) == sizeof(SOURCE), "can't convert");
union {
Expand Down

0 comments on commit 74ff9ca

Please sign in to comment.