Skip to content

Commit

Permalink
Resolve class/struct distinction warning from clang
Browse files Browse the repository at this point in the history
For these classes, we're declaring them a typedef with `struct NAME *`
in a `.h` file so that it can be used from C. But then the body is
defined in C++ with `class`. The clang compiler on Mac complains (but
says "I'm okay with this, but Microsoft might not be"). So it doesn't
really matter, but I'd rather get rid of the warnings if it doesn't
cost anything.

It's okay to use `struct` in C++ with inheritance and all the other
features of classes... the main difference is that `struct` members
are public by default vs `class` being private by default.

So here we turn all of these that use the typedef struct pointer C
into structs rather than classes, which silences the warnings.

```
In file included from ring.cpp:34:
./ring_impl.hpp:47:1: warning: class 'BFspan_impl' was previously declared as a
      struct; this is valid, but may result in linker errors under the Microsoft
      C++ ABI [-Wmismatched-tags]
class BFspan_impl;
^
./bifrost/ring.h:67:16: note: previous use is here
typedef struct BFspan_impl*        BFspan;
               ^
```
  • Loading branch information
league committed Mar 29, 2022
1 parent 7790fdb commit 3e3f580
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/proclog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class movable_ofstream_WAR {
}
};

class BFproclog_impl {
struct BFproclog_impl {
private:
friend class ProcLogStream;
std::string _filename;
public:
Expand Down
32 changes: 19 additions & 13 deletions src/ring_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@
#include <memory>

class BFsequence_impl;
class BFspan_impl;
class BFrspan_impl;
class BFwspan_impl;
struct BFspan_impl;
struct BFrspan_impl;
struct BFwspan_impl;
class RingReallocLock;
class Guarantee;
typedef std::shared_ptr<BFsequence_impl> BFsequence_sptr;

class BFring_impl {
friend class BFrsequence_impl;
friend class BFwsequence_impl;
struct BFring_impl {
private:
friend struct BFrsequence_impl;
friend struct BFwsequence_impl;
friend class RingReallocLock;
friend class Guarantee;

Expand Down Expand Up @@ -256,7 +257,7 @@ inline std::unique_ptr<Guarantee> new_guarantee(BFring ring) {
}

class BFsequence_impl {
friend class BFring_impl;
friend struct BFring_impl;
enum { BF_SEQUENCE_OPEN = (BFoffset)-1 };
BFring _ring;
std::string _name;
Expand Down Expand Up @@ -290,7 +291,7 @@ class BFsequence_impl {
inline BFoffset end() const { return _end; }
};

class BFsequence_wrapper {
struct BFsequence_wrapper {
protected:
BFsequence_sptr _sequence;
public:
Expand All @@ -306,7 +307,8 @@ class BFsequence_wrapper {
inline BFoffset begin() const { return _sequence->begin(); }
};

class BFwsequence_impl : public BFsequence_wrapper {
struct BFwsequence_impl : public BFsequence_wrapper {
private:
BFoffset _end_offset_from_head;
BFwsequence_impl(BFwsequence_impl const& ) = delete;
BFwsequence_impl& operator=(BFwsequence_impl const& ) = delete;
Expand All @@ -333,7 +335,8 @@ class BFwsequence_impl : public BFsequence_wrapper {
}
};

class BFrsequence_impl : public BFsequence_wrapper {
struct BFrsequence_impl : public BFsequence_wrapper {
private:
std::unique_ptr<Guarantee> _guarantee;
public:
// TODO: See if can make these function bodies a bit more concise
Expand Down Expand Up @@ -376,7 +379,8 @@ class BFrsequence_impl : public BFsequence_wrapper {
*/
};

class BFspan_impl {
struct BFspan_impl {
private:
BFring _ring;
BFsize _size;
// No copy or move
Expand All @@ -401,7 +405,8 @@ class BFspan_impl {
virtual void* data() const = 0;
virtual BFoffset offset() const = 0;
};
class BFwspan_impl : public BFspan_impl {
struct BFwspan_impl : public BFspan_impl {
private:
BFoffset _begin;
BFsize _commit_size;
void* _data;
Expand All @@ -423,7 +428,8 @@ class BFwspan_impl : public BFspan_impl {
// Can't easily change the name though because it's a shared API
inline virtual BFoffset offset() const { return _begin; }
};
class BFrspan_impl : public BFspan_impl {
struct BFrspan_impl : public BFspan_impl {
private:
BFrsequence _sequence;
BFoffset _begin;
void* _data;
Expand Down
3 changes: 2 additions & 1 deletion src/udp_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,8 @@ inline uint64_t round_nearest(uint64_t val, uint64_t mult) {
return (2*val/mult+1)/2*mult;
}

class BFudpcapture_impl {
struct BFudpcapture_impl {
private:
UDPCaptureThread _capture;
CHIPSDecoder _decoder;
CHIPSProcessor8bit _processor;
Expand Down
3 changes: 2 additions & 1 deletion src/udp_transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ class UDPTransmitThread : public BoundThread {
}
};

class BFudptransmit_impl {
struct BFudptransmit_impl {
private:
UDPTransmitThread _transmit;
ProcLog _type_log;
ProcLog _bind_log;
Expand Down

0 comments on commit 3e3f580

Please sign in to comment.