Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ esac
AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[CXXFLAGS="$CXXFLAGS -fvisibility=hidden"],[],[$CXXFLAG_WERROR])

## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
## unknown options if any other warning is produced. Test the -Wfoo case, and
## set the -Wno-foo case if it works.
AX_CHECK_COMPILE_FLAG([-Wshift-count-overflow],[NOWARN_CXXFLAGS="$NOWARN_CXXFLAGS -Wno-shift-count-overflow"],,[[$CXXFLAG_WERROR]])

if test "x$use_ccache" != "xno"; then
AC_MSG_CHECKING(if ccache should be used)
if test x$CCACHE = x; then
Expand Down
20 changes: 16 additions & 4 deletions src/int_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ class BitWriter {
int offset = 0;
unsigned char* out;

public:
BitWriter(unsigned char* output) : out(output) {}

template<int BITS, typename I>
inline void Write(I val) {
inline void WriteInner(I val) {
// We right shift by up to 8 bits below. Verify that's well defined for the type I.
static_assert(std::numeric_limits<I>::digits > 8, "BitWriter::WriteInner needs I > 8 bits");
int bits = BITS;
if (bits + offset >= 8) {
state |= ((val & ((I(1) << (8 - offset)) - 1)) << offset);
Expand All @@ -78,6 +77,19 @@ class BitWriter {
offset += bits;
}


public:
BitWriter(unsigned char* output) : out(output) {}

template<int BITS, typename I>
inline void Write(I val) {
Comment on lines +84 to +85
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether inline makes anything for templates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline has two meanings in C++:

  • A semantic one, permitting multiple identical definitions in separate translation units.
  • A hint for the compiler that inlining the function is desired.

The first one is always true for templated things, but the second one isn't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • A hint for the compiler that inlining the function is desired.

I thought that C++ standard abandoned this meaning of the inline keyword, especially since C++17.

https://en.cppreference.com/w/cpp/language/inline

Of course, compilers could have different opinions :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're misreading that page. The C++17 specific boxes explain that variables can be inline too now, justified by the fact that inline has ended up meaning "multiple definitions are allowed". It doesn't say anything about whether compilers do or don't also take inline into account for making inlining decisions (which isn't possible anyway, as there is no observable effect from the perspective of language definition).

// If I is smaller than an unsigned int, invoke WriteInner with argument converted to unsigned.
using compute_type = typename std::conditional<
(std::numeric_limits<I>::digits < std::numeric_limits<unsigned>::digits),
unsigned, I>::type;
return WriteInner<BITS, compute_type>(val);
}

inline void Flush() {
if (offset) {
*(out++) = state;
Expand Down