Skip to content

Commit

Permalink
Merge pull request #192 from aminya/c-exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 19, 2023
2 parents 828bc6b + 6ad95df commit 3d0e129
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 62 deletions.
2 changes: 2 additions & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ language: en, en-GB
allowCompoundWords: true
enableGlobDot: true
words:
- awalsh
- pkgs
- aarch
- aminya
- Amnet
Expand Down
13 changes: 8 additions & 5 deletions src/Optimization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ endmacro()

# Disable C++ exceptions for the given project.
macro(disable_exceptions _project_name)
target_compile_options(${_project_name} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/EHs-c- /D_HAS_EXCEPTIONS=0>)
target_compile_options(${_project_name} INTERFACE $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fno-exceptions
-fno-unwind-tables>)
target_compile_options(${_project_name} INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/EHs-c-
/D_HAS_EXCEPTIONS=0>)
target_compile_options(
${_project_name} INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fno-exceptions
-fno-unwind-tables>)
endmacro()

# Disable C++ RTTI (Run-Time Type Information) for the given project.
macro(disable_rtti _project_name)
target_compile_options(${_project_name} INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/GR->)
target_compile_options(${_project_name} INTERFACE $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fno-rtti>)
target_compile_options(${_project_name} INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/GR->)
target_compile_options(${_project_name}
INTERFACE $<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:-fno-rtti>)
endmacro()
4 changes: 2 additions & 2 deletions tests/emscripten/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#endif

int main() {
printf("hello, world!\n");
return 0;
printf("hello, world!\n");
return 0;
}
4 changes: 2 additions & 2 deletions tests/install/src/another_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#include <mylib2/lib.hpp>

int main() {
some_fun2();
return some_fun2();
some_fun2();
return some_fun2();
}
4 changes: 2 additions & 2 deletions tests/minimal/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/core.h>

int main() {
fmt::print("Hello World!");
return 0;
fmt::print("Hello World!");
return 0;
}
12 changes: 6 additions & 6 deletions tests/myproj/include/mylib/lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#include <cstring>

int some_fun() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

// populate an Eigen vector with the values
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);
// populate an Eigen vector with the values
auto eigen_vec = Eigen::VectorXd::LinSpaced(10, 0, 1);

// print the vector
fmt::print("{}", eigen_vec);
// print the vector
fmt::print("{}", eigen_vec);

return 0;
return 0;
}
18 changes: 9 additions & 9 deletions tests/myproj/libs/mythirdpartylib/include/Foo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
namespace mythirdpartylib {

class MYTHIRDPARTYLIB_EXPORT Foo {
public:
Foo() = default;
public:
Foo() = default;

/*implicit*/ Foo(int a) : m_a(a) {}
/*implicit*/ Foo(int a) : m_a(a) {}

int a() const { return m_a; }
int a() const { return m_a; }

void update(bool b, bool c, bool d);
void bad(std::vector<std::string> &v);
void update(bool b, bool c, bool d);
void bad(std::vector<std::string> &v);

private:
int m_a;
private:
int m_a;
};

}// namespace mythirdpartylib
} // namespace mythirdpartylib
20 changes: 10 additions & 10 deletions tests/myproj/libs/mythirdpartylib/src/Foo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
namespace mythirdpartylib {

void Foo::update(bool b, bool c, bool d) {
int e = b + d;
m_a = e;
int e = b + d;
m_a = e;
}

void Foo::bad(std::vector<std::string> &v) {
std::string val = "hello";
int index = -1;// bad, plus should use gsl::index
for (int i = 0; i < v.size(); ++i) {
if (v[i] == val) {
index = i;
break;
}
std::string val = "hello";
int index = -1; // bad, plus should use gsl::index
for (int i = 0; i < v.size(); ++i) {
if (v[i] == val) {
index = i;
break;
}
}
}

static Foo foo(5);
static Foo bar = 42;

}// namespace mythirdpartylib
} // namespace mythirdpartylib
22 changes: 11 additions & 11 deletions tests/myproj/src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
#include <cstring>

int main() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);

#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#endif

// trigger address sanitizer
// int *p = nullptr;
// *p = 1;
// trigger address sanitizer
// int *p = nullptr;
// *p = 1;

// trigger compiler warnings, clang-tidy, and cppcheck
int a;
// trigger compiler warnings, clang-tidy, and cppcheck
int a;
}
14 changes: 7 additions & 7 deletions tests/myproj/src/mylib2/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#include <cstring>

int some_fun2() {
fmt::print("Hello from fmt{}", "!");
fmt::print("Hello from fmt{}", "!");

Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);
Eigen::VectorXd eigen_vec = Eigen::Vector3d(1, 2, 3);
fmt::print("{}", eigen_vec);

#if !defined(__MINGW32__) && !defined(__MSYS__)// TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#if !defined(__MINGW32__) && !defined(__MSYS__) // TODO fails
Eigen::VectorXd eigen_vec2 = Eigen::VectorXd::LinSpaced(10, 0, 1);
fmt::print("{}", eigen_vec2);
#endif

return 0;
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi3/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>

int main() {
printf("Hello World\n");
return 0;
printf("Hello World\n");
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi3/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
std::cout << "Hello World!";
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi4-vcpkg/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <fmt/core.h>

int main() {
fmt::print("Hello World!");
return 0;
fmt::print("Hello World!");
return 0;
}
4 changes: 2 additions & 2 deletions tests/rpi4/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>

int main() {
std::cout << "Hello World!";
return 0;
std::cout << "Hello World!";
return 0;
}

0 comments on commit 3d0e129

Please sign in to comment.