I am reading a wav file,and pushing the data in a std::array in the end.
I need to make some operation on the chunks of data. So I thought this is a good opportunity to learn Eric Niebler's ranges.
I saw view_facade in manual page under "custom ranges" section but than I saw this question: link . Now I am not sure how to make a custom range class. Can anybody help me about that? The code below shows what I am trying to achieve.
#include <iostream>
#include <range/v3/all.hpp>
using namespace ranges;
using namespace std;
struct A
{
static constexpr size_t MAX_SIZE = 100000;
A ()
{
for ( size_t i = 0; i < MAX_SIZE; i++)
data[i] = i;
size = MAX_SIZE;
}
auto begin() const { return data.begin(); }
auto end() const { return data.end(); }
std::array< double , MAX_SIZE > data;
size_t size;
};
int main()
{
A instance;
RANGES_FOR(auto chunk, view::all(instance) | view::chunk(256)) {
}
return 0;
}
Part of compile output:
14:47:23: Running steps for project tryOuts...
14:47:23: Configuration unchanged, skipping qmake step.
14:47:23: Starting: "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe"
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Erdem/Documents/build-tryOuts-Desktop_Qt_5_4_2_MinGW_32bit-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -std=gnu++1y -pthread -lpthread -O3 -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -I"..\tryOuts" -I"." -I"..\..\..\..\range-v3-master\include" -I"D:\cvOutNoIPP\install\include" -I"..\..\..\..\Qt\5.4\mingw491_32\mkspecs\win32-g++" -o debug\main.o ..\tryOuts\main.cpp
In file included from ..\..\..\..\range-v3-master\include/range/v3/utility/iterator.hpp:28:0,
from ..\..\..\..\range-v3-master\include/range/v3/begin_end.hpp:24,
from ..\..\..\..\range-v3-master\include/range/v3/core.hpp:17,
from ..\..\..\..\range-v3-master\include/range/v3/all.hpp:17,
from ..\tryOuts\main.cpp:2:
..\..\..\..\range-v3-master\include/range/v3/utility/basic_iterator.hpp:445:22: error: 'constexpr const T& ranges::v3::basic_mixin<Cur>::get() const' cannot be overloaded
T const &get() const noexcept
^
------------ Update -------------------------------------------
If I add
CONFIG += c++14 the code almost compiles except auto return type deduction errors below :
main.cpp:22: deduced return type only available with -std=c++1y or -std=gnu++1y
to avoid those errors I am using CONFIG += c++1y.But in this case I am getting bunch of errors that I post in first place. I know from D language so called "Voldemort Types" are important, I don't want to give up return type deduction. Which flag in gcc should I use?
I'm still learning the range library myself, but my understanding is that things that expose STL-compatible begin() and end() methods can be used as a view. So for example, with your Reader class you could have
struct Reader {
// ...
auto begin() const { return rawData.begin(); }
auto end() const { return rawData.end(); }
};
You could then use view::all() to create a view around the Reader, something like
Reader r;
RANGES_FOR(auto chunk, view::all(r) | view::chunk(256)) {
...
}
As I say, I'm still learning the library myself, but hopefully this will help.
Related
I compiled my code with the same version of GCC using both -std=gnu++17 and -std=gnu++20. This warning appears for c++17 but is NOT present when using c++20.
I am going to state right up front that, try as I might, I have been unable to create a minimum reproducible example of this problem, but I will continue to try. In the absence of an example, I am just looking for some guidance or would like to know if anyone has ever encountered a similar problem.
I am encountering a large number of the following warnings in my code:
left shift of negative value [-Wshift-negative-value]
The odd thing is, the place where the error is occurring is on the following lines which occur all over my code (as part of a state machine framework):
CState(static_cast<CState::State>(...))
Where CState and State are:
class CState {
public:
using State = CState (AbstractStateMachineV2::*)(const AbstractEventV2&);
constexpr CState(State fn = nullptr) : _fn(fn) {}
static constexpr CState null() { return CState(); }
inline CState operator()(AbstractStateMachineV2& context, const AbstractEventV2& e) {
return context.call(_fn, e);
}
inline operator bool() const { return _fn != nullptr; }
inline bool operator==(CState const& other) { return _fn == other._fn;}
inline bool operator!=(CState const& other) { return _fn != other._fn;}
private:
State _fn;
};
Where the value being casted is just a pointer to a member method used like so:
class MyStateMachine : public AbstractStateMachineV2
{
protected:
CState myState(const AbstractEventV2& e);
};
auto s = CState(static_cast<CState::State>(&MyStateMachine::myState));
As you can see, there is no shifting being done here. And none of the other code that I didn't show involves shifting either.
Unfortunately, I can provide no further insight than this.
I am using the following GCC version but also get the same results on the latest version:
arm-none-eabi-g++.exe (GNU Tools for STM32 10.3-2021.10.20211105-1100) 10.3.1 20210824 (release)
I would really appreciate even the smallest bit of insight anyone could provide on this.
I don't know if this will help at all, but here is a snippet of the actual compilation output for a single source file of my project:
arm-none-eabi-g++ -g3 --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -O1 -Wno-missing-field-initializers --debug -g -DBUILD_VERSION_RELEASE=0 -DBUILD_VERSION_MAJOR=0 -DBUILD_VERSION_MINOR=0 -DBUILD_VERSION_BUILD=0 -DBUILD_VERSION_STEM="'a'" -DBUILD_VERSION=\"\" -DUNIX_TIMESTAMP_COMPILE_DATE=\""NO-COMPILE-TIME-PROVIDED"\" -DCOMPILE_BRANCH=\""no-branch"\" -DCODE_REVISION=\""0000000000000000000000000000000000000000"\" -DCODE_REVISION_HASH="{"0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00"}" -DPROJECT_NAME=\"prj-tw-av-base\" -DBUILD_CONFIGURATION=\"debug\" -DBUILD_TARGET_ARCH=\"stm32l562xx\" -DNULL=0 -DDEBUG=1 -DHAVE_CONFIG_H -DOPUS_ARM_ASM -DTW_DEBUG=1 -DLFS_THREADSAFE=1 -DUSE_HAL_DRIVER -DSTM32L562xx -DUSE_FULL_LL_DRIVER -fdata-sections -ffunction-sections -fstack-usage -mcpu=cortex-m33 -MMD -MP -mthumb -Wall -Wextra -mfpu=fpv5-sp-d16 -mfloat-abi=hard -c -std=gnu++17 -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Wdelete-non-virtual-dtor -Wno-volatile -Ilibraries/lib-ext-ctti/include/ -Ilibraries/lib-ext-etl/include/ -Ilibraries/lib-gsp-core-framework/include/ -Ilibraries/lib-tw-av-base-littlefs/include/ -Isources/prj-tw-av-base/include -Isources/prj-tw-av-base/private-include -Itwframework/include -Itwstm32/include -Itwcommon/include -Itwstm32/freertos/include -Itwstm32/stm32cube/STM32L5xx_HAL_Driver/Inc -Itwstm32/stm32cube/CMSIS/Device/ST/STM32L5xx/Include -Itwstm32/stm32cube/CMSIS/Include -Itwstm32/freertos/portable/GCC/ARM_CM33_NTZ/non_secure -Iavbase/include -Iconfig/include -Itwinnet/include -Ist8500/include -Itwfreertos/include -Itwstm32/stm32cube/STM32L5xx_HAL_Driver/Inc/Legacy -Iseggersystemview/include -Iopus/include -Iopus/silk -Iopus/celt -Iopus -Iopus/silk/fixed -Iopus/silk/arm -Iopus/silk/fixed/arm -Iopus/celt/arm -o "build/stm32l562xx/debug/obj/./avbase/src/tw/avbase/filesystem/FilesystemSubsystem.cpp.obj" "avbase/src/tw/avbase/filesystem/FilesystemSubsystem.cpp"
In file included from twframework/include/tw/statemachinev2/StateMachine.h:10,
from avbase/include/tw/avbase/filesystem/FilesystemSubsystem.h:26,
from avbase/src/tw/avbase/filesystem/FilesystemSubsystem.cpp:10:
avbase/include/tw/avbase/filesystem/FilesystemSubsystem.h: In static member function 'static constexpr tw::AbstractStateMachineV2::CState tw::avbase::FilesystemSubsystem::sFS_INFO::init()':
twframework/include/tw/statemachinev2/macros.h:31:89: warning: left shift of negative value [-Wshift-negative-value]
31 | static constexpr CState init() { return CState(static_cast<CState::State>(&init_)); }\
| ^
twframework/include/tw/statemachinev2/macros.h:19:50: note: in expansion of macro '_TW_DECLARE_STATE3'
19 | #define _TW_DECLARE_STATEN(_1, _2, _3, FN_, ...) FN_
| ^~~
twframework/include/tw/statemachinev2/macros.h:18:31: note: in expansion of macro '_TW_DECLARE_STATEN'
18 | #define TW_DECLARE_STATE(...) _TW_DECLARE_STATEN(__VA_ARGS__, _TW_DECLARE_STATE3, _TW_DECLARE_STATE2, _TW_DECLARE_STATE1)(__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~
avbase/include/tw/avbase/filesystem/FilesystemSubsystem.h:77:2: note: in expansion of macro 'TW_DECLARE_STATE'
77 | TW_DECLARE_STATE(sFS, FilesystemSubsystem::top, FilesystemSubsystem::sFSIdle);
| ^~~~~~~~~~~~~~~~
avbase/src/tw/avbase/filesystem/FilesystemSubsystem.cpp: In constructor 'tw::avbase::FilesystemSubsystem::FilesystemSubsystem(tw::AbstractActiveThread&, tw::twfs::AbstractFilesystem&, tw::twinnet::app::MessageRouter&, tw::twinnet::app::SubAddress, const char*, tw::logging::AbstractLoggable*)':
twframework/include/tw/statemachinev2/macros.h:161:54: warning: left shift of negative value [-Wshift-negative-value]
161 | transition(CState(static_cast<CState::State>(&state_)))
| ^
avbase/src/tw/avbase/filesystem/FilesystemSubsystem.cpp:39:2: note: in expansion of macro 'TW_INITIAL_TRANSITION'
39 | TW_INITIAL_TRANSITION(FilesystemSubsystem::sFS);
| ^~~~~~~~~~~~~~~~~~~~~
...
Every time I do that function pointer casting (via a helper macro), a warning is generated.
The warning is even generated if I add a line as simple as:
FilesystemSubsystem::FilesystemSubsystem()
{
//Warning generated at the following line
auto s = CState(static_cast<CState::State>(&FilesystemSubsystem::state1));
}
AbstractStateMachineV2::CState FilesystemSubsystem::state1(const AbstractEventV2& _e)
{
//...
}
This makes me start to wonder if there is some sort of really odd compiler bug that is exhibiting itself.
I run an up to date debian testing (with kernel 4.19).
Helpers are not found on my system (but they exist in the header, Qt jumps to them)
#include "bpf/bpf.h"
int main (){
int r = bpf_create_map(BPF_MAP_TYPE_ARRAY,1,1,1,0);
return 0;
}
Compilation results in
undefined reference to `bpf_create_map(bpf_map_type, int, int, int, unsigned int)'
compiled with
g++ -c -pipe -g -std=gnu++1z -Wall -W -fPIC -DQT_QML_DEBUG -I. -I../../Qt/5.13.0/gcc_64/mkspecs/linux-g++ -o main.o main.cpp
g++ -lbpf -o server main.o
Same result with
g++ main.cpp -lbpf -o out
I have the libbpf-dev installed as well and i have the associated libraries (a and so).
What is wrong?
Update
even the following code won't work
#include <linux/bpf.h>
int main (){
//int r = bpf_create_map(BPF_MAP_TYPE_ARRAY,1,1,1,0);
bpf_attr attr = {};
attr.map_type = BPF_MAP_TYPE_ARRAY;
attr.key_size = 1;
attr.value_size = 1;
attr.max_entries = 1;
bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
return 0;
}
results in
error: 'bpf' was not declared in this scope
Update2:
BTW, key size is mandated to be 4 and not 1; but it is a point aside, that was unrelated to my problem here.
Namespace issue due to compiling in C++, you probably want:
extern "C" {
#include "bpf/bpf.h"
}
int main()...
Regarding your second error (error: 'bpf' was not declared in this scope), this is not directly related to libbpf, this is because there is no function simply called bpf() to actually perform the syscall. Instead you have to use the syscall number. For example, libbpf defines the following:
static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
unsigned int size)
{
return syscall(__NR_bpf, cmd, attr, size);
}
... and uses sys_bpf() after that, the same way you try to call bpf() in your sample.
For the record, “BPF helpers” often designates BPF functions that you call from within a BPF program, which is not the case here. Hence some confusion in the comments, I believe.
First the code:
#pragma once
#include <type_traits>
// assign unique identifiers to types
template<typename ...>
class Family
{
static std::size_t identifier() noexcept
{
static std::size_t value = 0;
return value++;
}
template<typename ...>
static std::size_t family() noexcept
{
static const std::size_t value = identifier();
return value;
}
public:
using family_type = std::size_t;
template<typename ... Type>
static family_type type() noexcept
{
return family<std::decay_t<Type>...>();
}
};
// usage
using introspection_family = Family<struct IntrospectionRegistry>;
template<typename Structure>
void addIntrospectData(DataType introspection[MAX_TYPES], DataType const& dataType)
{
/* reserve index for this type in the introspection register */
const auto num = introspection_family::type<Structure>();
assert(num < MAX_TYPES);
introspection[num - 1] = dataType;
}
This code give an integer to each type and I use it in some kind of C++ introspection implementation.
The application isn't multi threaded.
When I compiled it in -O0, sometimes, the call to introspection_family::type<Structure>() blocks at __cxa_guard_acquire#plt and I get a deadlock.
When compiled with -O3, I don't have any problem, but that might just be because it becomes very difficult to reproduce.
__cxa_guard_acquire is used to ensure that the static variable is constructed before we access it but here it should be irrelevant as I'm not even in a threaded application.
Does anyone have any idea why this is happening ?
I use:
CXXFLAGS=-std=c++14 -O0 -g3 -pthread -Wall -Wextra -Werror
LDFLAGS= -g -pthread -lGLEW -lGLU -lGL -lSDL2_mixer -lSDL2
And I use gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609
Adding the compile option -fno-threadsafe-statics helped. Since your application is single thread, this is OK.
I had a similar issue. However, the reason in my code was recursion. __cxa_guard_acquire will block when called recursively. A proper fix was needed. I did not check your code if this could also be your problem.
Additional info: The lock used might have a different name than __cxa_guard_acquire. It might also work with recursion, but this is compiler/libc++ specific and you should not rely on that.
This question already has an answer here:
'noexcept = default' compilation error
(1 answer)
Closed 5 years ago.
(This is not a duplicate of another question since in the other one the question is about the compilation issue (where somebody suggested to implement a constructor), and here there is an specific question about how to implement that constructor manually)
In order to compile the following program with GCC 4.9.2, It has to be modified. I have to implement the constructor manually and I dont know how to do it.
The line 6 is causing trouble and is the one that needs to be modified:
'TabStats::TabStats(TabStats&& other) noexcept = default;'
As a condition, the no-except specifier cant be removed.
SOURCE CODE:
#include "browser/resource_coordinator/tab_stats.h"
#include "build/build_config.h"
namespace resource_coordinator {
TabStats::TabStats() = default;
TabStats::TabStats(const TabStats& other) = default;
TabStats::TabStats(TabStats&& other) noexcept = default;
TabStats::~TabStats() {}
TabStats& TabStats::operator=(const TabStats& other) = default;
} // namespace resource_coordinator
tab_stats.h is included below:
#ifndef BROWSER_RESOURCE_COORDINATOR_TAB_STATS_H_
#define BROWSER_RESOURCE_COORDINATOR_TAB_STATS_H_
#include <stdint.h>
#include <vector>
#include "base/process/process.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "build/build_config.h"
namespace content {
class RenderProcessHost;
} // namespace content
namespace resource_coordinator {
struct TabStats {
TabStats();
TabStats(const TabStats& other);
TabStats(TabStats&& other) noexcept;
~TabStats();
TabStats& operator=(const TabStats& other);
bool is_app = false; // Browser window is an app.
bool is_internal_page = false; // Internal page, such as NTP or Settings.
// Playing audio, accessing cam/mic or mirroring display.
bool is_media = false;
bool is_pinned = false;
bool is_in_visible_window = false;
bool is_in_active_window = false;
// Whether this is the active tab in a browser window.
bool is_active = false;
bool is_discarded = false;
// User has entered text in a form.
bool has_form_entry = false;
int discard_count = 0;
bool has_beforeunload_handler = false;
base::TimeTicks last_active;
base::TimeTicks last_hidden;
content::RenderProcessHost* render_process_host = nullptr;
base::ProcessHandle renderer_handle = 0;
int child_process_host_id = 0;
base::string16 title;
#if defined(OS_CHROMEOS)
int oom_score = 0;
#endif
int64_t tab_contents_id = 0; // Unique ID per WebContents.
bool is_auto_discardable = true;
};
typedef std::vector<TabStats> TabStatsList;
} // namespace resource_coordinator
#endif // BROWSER_RESOURCE_COORDINATOR_TAB_STATS_H_
This is the compilation error Im getting (I removed many flags to make this shorter):
[20689/29018] CXX obj/chrome/browser/browser/tab_stats.o
FAILED: obj/chrome/browser/browser/tab_stats.o
g++ -MMD -MF obj/chrome/browser/browser/tab_stats.o.d -DUSE_LIBSECRET -DV8_DEPRECATION_WARNINGS -DUSE_UDEV -DUSE_AURA=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_X11=1 -DNO_TCMALLOC -DDISABLE_NACL -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DCHROMIUM_BUILD -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -DNDEBUG -DUSE_CUPS -DUSE_GNOME_KEYRING -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32 -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26 -DUSE_GLX -DSK_SUPPORT_GPU=1 -DV8_USE_EXTERNAL_STARTUP_DATA -DWEBRTC_CHROMIUM_BUILD -DWEBRTC_POSIX -DWEBRTC_LINUX -DHUNSPELL_STATIC --param=ssp-buffer-size=4 -fstack-protector -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -funwind-tables -fPIC -pipe -pthread -m32 -msse2 -mfpmath=sse -mmmx -Wall -O2 -g0 -fvisibility=hidden -DLIBXML_STATIC= -std=gnu++11 -nostdinc++ -isystem../../buildtools/third_party/libc++/trunk/include -isystem../../buildtools/third_party/libc++abi/trunk/include -Wno-narrowing -fno-rtti -fno-exceptions -fvisibility-inlines-hidden -c ../../chrome/browser/resource_coordinator/tab_stats.cc -o obj/chrome/browser/browser/tab_stats.o
../../chrome/browser/resource_coordinator/tab_stats.cc:14:1: error: function 'resource_coordinator::TabStats::TabStats(resource_coordinator::TabStats&&)' defaulted on its redeclaration with an exception-specification that differs from the implicit declaration 'resource_coordinator::TabStats::TabStats(resource_coordinator::TabStats&&)'
TabStats::TabStats(TabStats&& other) noexcept = default;
^
There are only two cases when you should have to write your own move constructor, and both of them make little sense:
when one of the base classes does not have move semantics, but then having move semantics for your derived class does not make sense at all.
when one of your class data member does not have move semantics, but then having move semantics for your class does not quite make sense.
Usually this would involve replacing the move operation by a copy.
A good starting point for writing your own move constructor, is to do what the the compiler does:
Call the move constructors of base classes (You must use std::move).
Call the move contructor of all class members. (use std::move).
ex:
struct A {}; // must have a move constructor, be it a default or not.
struct B : A
{
B(B&& b)
: A(std::move(b))
, data1_(std::move(b.data1_))
, data2_(std::move(b.data2_))
{}
some_type data1_;
some_other_type data2_;
};
Nothing exciting here, which is why the default works in most cases. Classes that cannot be moved are pretty rare.
I'm experiencing a strange problem in one of my projects. My code base depends on an external library, which contains a class named Dataset. The Dataset class privately inherits from std::vector<Sample> (where Sample is another custom class defined in the library).
Moreover, such a class exposes a Save member function in order to serialize the data composing the data set into a text file. The Save member function is defined as follows:
inline void Dataset::Save(string filename, ModalityType modality)
{
ofstream log_file;
if (modality == OVERWRITE) {
log_file.open(filename.c_str());
} else {
log_file.open(filename.c_str(), ios::out | ios::app);
}
if (log_file.is_open()) {
log_file << *(this);
}
log_file.close();
}
ofstream& operator<< (ofstream& out, Dataset& ds)
{
unsigned int size = ds.size();
unsigned int input_size = ds.GetInputSize();
unsigned int output_size = ds.GetOutputSize();
out << input_size << " " << output_size << endl;
for (unsigned int i = 0; i < size; i++) {
Sample* s = ds[i];
for (unsigned int j = 0; j < input_size; j++) {
out << s->GetInput(j) << " ";
}
for (unsigned int j = 0; j < output_size; j++) {
out << s->GetOutput(j) << " ";
}
out << endl;
}
return out;
}
Both my code and the external library have been compiled under OS X 10.8.2 with clang 4.2 and flags -std=c++11 -stdlib=libc++. I need to do so, since my code base uses several C++11 facilities (e.g., random). Moreover, the library itself depends on boost, which in turn has been compiled with clang and C++11 support.
Everything compiles and works as expected by using the following Makefile:
CXX = clang++
CXXDIALECT = -std=c++11 -stdlib=libc++
DEFS = -DBOOST_NO_CXX11_NUMERIC_LIMITS
INCLUDE_DIRS = -I. -I/usr/local/include -I/usr/include -I/opt/local/include
LIB_DIRS = -L/usr/local/lib -L/opt/local/lib
LIBS = -lfitted -lgsl -lgslcblas -lboost_thread -lboost_program_options -lboost_regex -lboost_system
CINCLUDE = $(INCLUDE_DIRS)
CXXFLAGS = -Os $(CXXDIALECT) $(CINCLUDE) $(DEFS)
tests := main.cpp
sources := $(filter-out $(tests), $(wildcard *.cpp))
objects := $(patsubst %.cpp,%.o,$(sources))
main: $(objects)
$(CXX) $(CXXFLAGS) -o $# $#.cpp $(objects) $(LIBS) $(LIB_DIRS) -v
%.o : %.cpp
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $#
where libfitted is the name of the external library.
Nevertheless, I'm developing my code under XCode 4.6.2. The problem is that everytime I try run/debug the code in XCode, the Dataset.save member function triggers the following error:
and an empty dataset.txt file is created on disk. Here's a couple of screenshots of the stack trace:
Click here and here to view them in full size.
As reported in the screenshots, the problem seems to be in the ofstream.flush() member function.
Finally, I report the output of both make and xcodebuild
I really can't figure out why the same code, with the same compiler and libraries, executes correctly if compiled with the afore-mentioned Makefile, while it is not working if executed in XCode.
UPDATE #1: I just noticed that the code is debuggable in XCode (although not runnable) if I use as debugger GDB instead of LLDB, i.e., Dataset.save does not trigger the EXC_BAD_ACCESS error.
UPDATE #2: I recompiled the library with the -g -O0 flags so as to preserve debug symbols. The problem is that everytime a ofstream object is initialized in a Dataset's member function, the this pointer of the Dataset instance becomes NULL, i.e., the Dataset object is nullified. Consequently, each attempt to access any data member within the member function results in a EXC_BAD_ACCESS. This is one of the weirdest thing I've ever seen. Any idea on why this is happening?
Thanks.
The std::vector<...> class is not designed to be used as a base class. Using it as such leads to undefined behaviour (because of the lack of a virtual destructor, at least).
Item 35 in C++ Coding Standards (Sutter, Alexandrescu), named
Avoid inheriting from classes that were not designed to be base
classes.
might well be of help here.
Item 7 of Effective C++ (Meyers) discuss the issue with this example:
class SpecialString: public std::string{
...
}
At first glance, this may look innocuous, but if anywhere in an
application you somehow convert a pointer-to-SpecialString into a
pointer-to-string and you then use delete on the string pointer, you
are instantly transported to the realm of undefined behavior.