Skip to content

Commit

Permalink
+cxx/Macros.cxx: Unit tests. ?cxx/Macros.hxx:
Browse files Browse the repository at this point in the history
	Refactor, cleanup, misc fixes:
	Move `#include`'s to top (thus `namespace Susuwu {}` doesn't contain `#include`):
		?`macrosNoUniqueAddressTest`: separate from `SUSUWU_CXX20`,
		?`SUSUWU_CXX*`: move to top (due to `#include`),
	terminate English sentences (but not acronyms or source code) in comments with `.`,
	move `NOLINTBEGIN` out of `#if` block (it was in the block since the first diagnostic which it silences is in the block, but `NOLINTEND` isn't in the block),
	group `#define __WIN32__` close to `#define __POSIX_SOURCE`,
	remove extra `#define __POSIX_SOURCE`,
	?`SUSUWU_PRAGMA`, ?`SUSUWU_SH_ST`: comment has English fix,
	?`SUSUWU_SH_RUNTIME_COLORS`, ?`SUSUWU_SH_RUNTIME_OSC`: upgrade `#pragma message` (for early users) from `Notice:` to `Info:`.
	?`SUSUWU_UNREACHABLE`: "warning: found assert() that could be replaced by static_assert() [cert-dcl03-c,hicpp-static-assert,misc-static-assert]": suppress (can not use `static_assert` for this).

?`cxx/Macros.*xx`:
	?`macrosNoUniqueAddressTest`: is now `static`, move into `cxx/Macros.cxx`.
	+`macroTestsNoexcept`: has macro tests which were in `testHarnesses`, calls `macrosNoUniqueAddressTest`.

?`cxx/main.cxx`: ?`testHarnesses`:
	now calls `macroTestsNoexcept`.
	was `[[noreturn]]`, now has `return 0;`.
	comment purpose of `std::flush`.

?`build.sh`: compile `cxx/Macros.cxx` into `Macros.o`, link `Macros.o` into `a.out`.

?`posts/VirusAnalysis.md`: include all this, except 100 lines of: unused OSC `sh` commands + disabled colors.

Is progress to issue #14 .

Is followup to bdfb817 (?`cxx/Macros`: +`macrosNoUniqueAddressTest()`:) c23165a (Prefix `SUSUWU_` to macros) 7dcf2bc (...test `NOEXCEPT(condition)`.) ce649ab
(?cxx/Macros.hxx `clang-tidy` fixes).
  • Loading branch information
SwuduSusuwu committed Nov 10, 2024
1 parent bdfb817 commit 7dbb0db
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 175 deletions.
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ set -x
$CXX -x c -c ${sSRC}/../c/rfc6234/sha1.c
$CXX -x c -c ${sSRC}/../c/rfc6234/sha224-256.c
$CXX -x c -c ${sSRC}/../c/rfc6234/sha384-512.c
$CXX -c ${sSRC}/Macros.cxx
$CXX -c ${sSRC}/ClassSha2.cxx
$CXX -c ${sSRC}/ClassResultList.cxx
$CXX -c ${sSRC}/ClassSys.cxx
$CXX -c ${sSRC}/ClassCns.cxx
$CXX -c ${sSRC}/VirusAnalysis.cxx
$CXX -c ${sSRC}/AssistantCns.cxx
$CXX -c ${sSRC}/main.cxx
$CXX ${LD_FLAGS} sha1.o sha224-256.o sha384-512.o ClassSha2.o ClassResultList.o ClassSys.o ClassCns.o VirusAnalysis.o AssistantCns.o main.o
$CXX ${LD_FLAGS} sha1.o sha224-256.o sha384-512.o Macros.o ClassSha2.o ClassResultList.o ClassSys.o ClassCns.o VirusAnalysis.o AssistantCns.o main.o
STATUS=$?
set +x
if [ 0 -eq $STATUS ]; then
Expand Down
47 changes: 47 additions & 0 deletions cxx/Macros.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Licenses: allows all uses ("Creative Commons"/"Apache 2") */
#ifndef INCLUDES_cxx_Macros_cxx
#define INCLUDES_cxx_Macros_cxx
/* This is just unit tests. `Macros.hxx` has all which has actual use. */
#include "Macros.hxx" /* IF_SUSUWU_CPLUSPLUS SUSUWU_ASSUME SUSUWU_EXPECTS SUSUWU_ENSURES SUSUWU_NOEXCEPT SUSUWU_NORETURN SUSUWU_STATIC_ASSERT SUSUWU_UNREACHABLE */
#include IF_SUSUWU_CPLUSPLUS(<cstdlib>, <stdlib.h>) /* exit */
#ifdef SUSUWU_CXX11
# include <type_traits> /* is_empty */
#endif /* def SUSUWU_CXX11 */
namespace Susuwu {
static void macrosNoUniqueAddressTest() {
typedef class Zero {} Zero;
class SubClassWithBaseSubobject : public Zero {bool boo;};
class SubClassWithMemberSubobject {bool boo; public: Zero zero;};
class SubClassWithMemberSubobjectNoAddress {bool boo; public: SUSUWU_NO_UNIQUE_ADDRESS Zero zero;};
#ifdef SUSUWU_CXX11 /* this is true without C++11, but `std::is_empty` doesn't exist in C++98. */
SUSUWU_STATIC_ASSERT(std::is_empty<Zero>::value);
#endif /* def SUSUWU_CXX11 */
SUSUWU_STATIC_ASSERT(sizeof(bool) == sizeof(SubClassWithBaseSubobject));
SUSUWU_STATIC_ASSERT(sizeof(bool) < sizeof(SubClassWithMemberSubobject));
#ifdef SUSUWU_CXX20 /* `[[no_unique_address]]` */
SUSUWU_STATIC_ASSERT(sizeof(bool) == sizeof(SubClassWithMemberSubobjectNoAddress));
#else /* def SUSUWU_CXX20 else */
SUSUWU_STATIC_ASSERT(sizeof(bool) < sizeof(SubClassWithMemberSubobjectNoAddress));
#endif /* def SUSUWU_CXX20 else */
}
static const int noExcept() SUSUWU_NOEXCEPT(true);
SUSUWU_NORETURN static void noReturn();
static const int noExcept() SUSUWU_NOEXCEPT {return 0;}
static void noReturn() {exit(0);} /* NOLINT(concurrency-mt-unsafe): is unreachable code */
static constexpr /* TODO: SUSUWU_CONSTEXPR */ const int macrosTestImpl() SUSUWU_EXPECTS(true) SUSUWU_ENSURES(true) SUSUWU_NOEXCEPT {
return 0;
}
const int macrosTestsNoexcept() SUSUWU_NOEXCEPT {
SUSUWU_STATIC_ASSERT(0 == macrosTestImpl());
SUSUWU_ASSUME(true);
noExcept();
if(false) { /* NOLINT(readability-simplify-boolean-expr) */
SUSUWU_UNREACHABLE;
noReturn();
}
return 0;
}

}; /* namespace Susuwu */
#endif /* ndef INCLUDES_cxx_Macros_cxx */

Loading

0 comments on commit 7dbb0db

Please sign in to comment.