diff --git a/CMake/CMakeConfig/gcc11_linux_x86_64_release.cmake b/CMake/CMakeConfig/gcc11_linux_x86_64_release.cmake index 4432e47..7891e9a 100644 --- a/CMake/CMakeConfig/gcc11_linux_x86_64_release.cmake +++ b/CMake/CMakeConfig/gcc11_linux_x86_64_release.cmake @@ -62,8 +62,29 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries") # -Wconversion: Warn for implicit type conversions that may alter a value. # -pedantic: Enforce strict ISO compliance. # -Wshadow: Warn when a variable shadows another variable. +# +# Added Flags: +# -Werror: Treat all warnings as errors. +# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur. +# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration. +# -Wstrict-aliasing=2: Enforce strict aliasing rules. +# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive. +# -Wredundant-decls: Warn about redundant declarations. +# -Wcast-align: Warn about potentially unsafe alignment casts. +# -Wformat=2: Check printf/scanf format strings. +# -Wfloat-equal: Warn if floating-point values are used in equality comparisons. +# -fno-common: Prevent multiple definitions. +# -march=native: Optimize for the local machine architecture. +# -flto: Enable Link Time Optimization. +# -fstack-protector-strong: Enable stack protection. +# -D_FORTIFY_SOURCE=2: Enable additional compile-time and run-time checks for buffer overflows. #======================================================================= -set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations -v" CACHE STRING "Initial C++ Compiler Flags") +set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \ +-Werror -Wstrict-overflow=5 -Wmissing-prototypes \ +-Wstrict-aliasing=2 -Wundef -Wredundant-decls \ +-Wcast-align -Wformat=2 -Wfloat-equal \ +-fno-common -march=native -flto -fstack-protector-strong \ +-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C Compiler Flags") #----------------------------------------------------------------------- # Build-Type Specific C Flags @@ -84,6 +105,7 @@ set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG" CACHE STRING "C Compiler set(CMAKE_C_FLAGS_ALSAN_INIT "-fsanitize=address -fno-omit-frame-pointer" CACHE STRING "C Compiler Flags for Address Sanitizer") set(CMAKE_C_FLAGS_TSAN_INIT "-fsanitize=thread" CACHE STRING "C Compiler Flags for Thread Sanitizer") set(CMAKE_C_FLAGS_UBSAN_INIT "-fsanitize=undefined" CACHE STRING "C Compiler Flags for Undefined Behavior Sanitizer") +set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Flags for ReleaseWithO2") #======================================================================= # Compiler Configuration for C++ @@ -99,8 +121,34 @@ set(CMAKE_C_FLAGS_UBSAN_INIT "-fsanitize=undefined" CACHE STRING "C Compiler Fla # -Wold-style-cast: Warn about C-style casts. # -pedantic: Enforce strict ISO compliance. # -Wshadow: Warn when a variable shadows another variable. +# -Wno-error=deprecated-declarations: Do not treat deprecated declarations as errors. +# -v: Verbose output during compilation. +# +# Added Flags: +# -Werror: Treat all warnings as errors. +# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur. +# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration. +# -Wstrict-aliasing=2: Enforce strict aliasing rules. +# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive. +# -Wredundant-decls: Warn about redundant declarations. +# -Wcast-align: Warn about potentially unsafe alignment casts. +# -Wformat=2: Check printf/scanf format strings. +# -Wfloat-equal: Warn if floating-point values are used in equality comparisons. +# -fno-exceptions: Disable C++ exception handling. +# -fno-rtti: Disable Run-Time Type Information. +# -fno-common: Prevent multiple definitions. +# -march=native: Optimize for the local machine architecture. +# -flto: Enable Link Time Optimization. +# -fstack-protector-strong: Enable stack protection. +# -D_FORTIFY_SOURCE=2: Enable additional compile-time and run-time checks for buffer overflows. #======================================================================= -set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow" CACHE STRING "Initial C++ Compiler Flags") +set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \ +-pedantic -Wshadow -Wno-error=deprecated-declarations -v \ +-Werror -Wstrict-overflow=5 \ +-Wstrict-aliasing=2 -Wundef -Wredundant-decls \ +-Wcast-align -Wformat=2 -Wfloat-equal \ +-fno-exceptions -fno-rtti -fno-common -march=native -flto -fstack-protector-strong \ +-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C++ Compiler Flags") #----------------------------------------------------------------------- # Build-Type Specific C++ Flags @@ -154,6 +202,101 @@ set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Executable Linker Flags # Flags for RelWithDebInfo build: Include debug symbols. set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "-g" CACHE STRING "Executable Linker Flags for RelWithDebInfo") +# Flags for ReleaseWithO2 build: No additional flags. +set(CMAKE_EXE_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Executable Linker Flags for ReleaseWithO2") + +#======================================================================= +# Module Linker Flags +#======================================================================= +# +# Initial flags for the module linker applicable to all build types. +#======================================================================= +set(CMAKE_MODULE_LINKER_FLAGS_INIT "" CACHE STRING "Initial Module Linker Flags") + +#----------------------------------------------------------------------- +# Build-Type Specific Module Linker Flags +#----------------------------------------------------------------------- +# Flags for Debug build: No additional flags. +set(CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT "" CACHE STRING "Module Linker Flags for Debug") + +# Flags for MinSizeRel build: No additional flags. +set(CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL_INIT "" CACHE STRING "Module Linker Flags for MinSizeRel") + +# Flags for Release build: No additional flags. +set(CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Module Linker Flags for Release") + +# Flags for RelWithDebInfo build: No additional flags. +set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Module Linker Flags for RelWithDebInfo") + +# Flags for ReleaseWithO2 build: No additional flags. +set(CMAKE_MODULE_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Module Linker Flags for ReleaseWithO2") + +#======================================================================= +# Shared Library Linker Flags +#======================================================================= +# +# Initial flags for the shared library linker applicable to all build types. +#======================================================================= +set(CMAKE_SHARED_LINKER_FLAGS_INIT "" CACHE STRING "Initial Shared Library Linker Flags") + +#----------------------------------------------------------------------- +# Build-Type Specific Shared Library Linker Flags +#----------------------------------------------------------------------- +# Flags for Debug build: No additional flags. +set(CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT "" CACHE STRING "Shared Library Linker Flags for Debug") + +# Flags for MinSizeRel build: No additional flags. +set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL_INIT "" CACHE STRING "Shared Library Linker Flags for MinSizeRel") + +# Flags for Release build: No additional flags. +set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Shared Library Linker Flags for Release") + +# Flags for RelWithDebInfo build: No additional flags. +set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Shared Library Linker Flags for RelWithDebInfo") + +# Flags for ReleaseWithO2 build: No additional flags. +set(CMAKE_SHARED_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Shared Library Linker Flags for ReleaseWithO2") + +#======================================================================= +# Static Library Linker Flags +#======================================================================= +# +# Initial flags for the static library linker applicable to all build types. +#======================================================================= +set(CMAKE_STATIC_LINKER_FLAGS_INIT "" CACHE STRING "Initial Static Library Linker Flags") + +#----------------------------------------------------------------------- +# Build-Type Specific Static Library Linker Flags +#----------------------------------------------------------------------- +# Flags for Debug build: No additional flags. +set(CMAKE_STATIC_LINKER_FLAGS_DEBUG_INIT "" CACHE STRING "Static Library Linker Flags for Debug") + +# Flags for MinSizeRel build: No additional flags. +set(CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL_INIT "" CACHE STRING "Static Library Linker Flags for MinSizeRel") + +# Flags for Release build: No additional flags. +set(CMAKE_STATIC_LINKER_FLAGS_RELEASE_INIT "" CACHE STRING "Static Library Linker Flags for Release") + +# Flags for RelWithDebInfo build: No additional flags. +set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Static Library Linker Flags for RelWithDebInfo") + +# Flags for ReleaseWithO2 build: No additional flags. +set(CMAKE_STATIC_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Static Library Linker Flags for ReleaseWithO2") + +#======================================================================= +# AUTOSAR Specific Compiler Flags +#======================================================================= +# +# AUTOSAR provides specific guidelines and macros. Depending on the GCC +# compiler support, you may need to define additional macros or flags. +# +# Example: +# -D_AUTOSAR=4.2.2: Define AUTOSAR version. +# -DAUTOSAR_COMPILATION: Enable AUTOSAR-specific compilation paths. +#======================================================================= +set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C Compiler Flags with AUTOSAR") +set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C++ Compiler Flags with AUTOSAR") + #======================================================================= # Additional CMake Settings #======================================================================= @@ -165,4 +308,4 @@ set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "-g" CACHE STRING "Executable Lin # Example: # set(SOME_PROJECT_VARIABLE "value" CACHE STRING "Description of the variable") # -#======================================================================= \ No newline at end of file +#======================================================================= diff --git a/CMake/CMakeConfig/qcc12_qnx800_aarch64_release.cmake b/CMake/CMakeConfig/qcc12_qnx800_aarch64_release.cmake index cfc09a9..527ea05 100644 --- a/CMake/CMakeConfig/qcc12_qnx800_aarch64_release.cmake +++ b/CMake/CMakeConfig/qcc12_qnx800_aarch64_release.cmake @@ -77,8 +77,25 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries") # -pedantic: Enforce strict ISO compliance. # -Wshadow: Warn when a variable shadows another variable. # -D_QNX_SOURCE: Define _QNX_SOURCE macro for QNX-specific features. +# +# Added Flags: +# -Werror: Treat all warnings as errors. +# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur. +# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration. +# -Wstrict-aliasing=2: Enforce strict aliasing rules. +# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive. +# -Wredundant-decls: Warn about redundant declarations. +# -Wcast-align: Warn about potentially unsafe alignment casts. +# -Wformat=2: Check printf/scanf format strings. +# -Wfloat-equal: Warn if floating point values are used in equality comparisons. +# -fno-common: Prevent multiple definitions. +# -mcpu=generic: Optimize for generic AArch64 architecture. #======================================================================= -set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow -D_QNX_SOURCE" CACHE STRING "Initial C Compiler Flags") +set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow -D_QNX_SOURCE \ +-Werror -Wstrict-overflow=5 -Wmissing-prototypes \ +-Wstrict-aliasing=2 -Wundef -Wredundant-decls \ +-Wcast-align -Wformat=2 -Wfloat-equal \ +-fno-common -mcpu=generic" CACHE STRING "Initial C Compiler Flags") #----------------------------------------------------------------------- # Build-Type Specific C Flags @@ -118,8 +135,26 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla # -Wno-error=deprecated-declarations: Do not treat deprecated declarations as errors. # -v: Verbose output during compilation. # -D_QNX_SOURCE: Define _QNX_SOURCE macro for QNX-specific features. +# +# Added Flags: +# -Werror: Treat all warnings as errors. +# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur. +# -Wstrict-aliasing=2: Enforce strict aliasing rules. +# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive. +# -Wredundant-decls: Warn about redundant declarations. +# -Wcast-align: Warn about potentially unsafe alignment casts. +# -Wformat=2: Check printf/scanf format strings. +# -Wfloat-equal: Warn if floating point values are used in equality comparisons. +# -fno-exceptions: Disable C++ exception handling. +# -fno-rtti: Disable Run-Time Type Information. +# -mcpu=generic: Optimize for generic AArch64 architecture. #======================================================================= -set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations -v -D_QNX_SOURCE" CACHE STRING "Initial C++ Compiler Flags") +set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \ +-pedantic -Wshadow -Wno-error=deprecated-declarations -v -D_QNX_SOURCE \ +-Werror -Wstrict-overflow=5 \ +-Wstrict-aliasing=2 -Wundef -Wredundant-decls \ +-Wcast-align -Wformat=2 -Wfloat-equal \ +-fno-exceptions -fno-rtti -mcpu=generic" CACHE STRING "Initial C++ Compiler Flags") #----------------------------------------------------------------------- # Build-Type Specific C++ Flags @@ -254,6 +289,20 @@ set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO_INIT "" CACHE STRING "Static Librar # Flags for ReleaseWithO2 build: No additional flags. set(CMAKE_STATIC_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Static Library Linker Flags for ReleaseWithO2") +#======================================================================= +# AUTOSAR Specific Compiler Flags +#======================================================================= +# +# AUTOSAR provides specific guidelines and macros. Depending on the QCC +# compiler support, you may need to define additional macros or flags. +# +# Example: +# -D_AUTOSAR=4.2.2: Define AUTOSAR version. +# -DAUTOSAR_COMPILATION: Enable AUTOSAR-specific compilation paths. +#======================================================================= +set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C Compiler Flags with AUTOSAR") +set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -D_AUTOSAR=4.2.2 -DAUTOSAR_COMPILATION" CACHE STRING "Initial C++ Compiler Flags with AUTOSAR") + #======================================================================= # Additional CMake Settings #======================================================================= @@ -266,4 +315,3 @@ set(CMAKE_STATIC_LINKER_FLAGS_RELEASEWITHO2_INIT "" CACHE STRING "Static Library # set(SOME_PROJECT_VARIABLE "value" CACHE STRING "Description of the variable") # #======================================================================= - diff --git a/CMake/Toolchain/CMakeLogging/tool_chain_log_config.cmake b/CMake/Toolchain/CMakeLogging/tool_chain_log_config.cmake index ae43e4e..f28c15e 100644 --- a/CMake/Toolchain/CMakeLogging/tool_chain_log_config.cmake +++ b/CMake/Toolchain/CMakeLogging/tool_chain_log_config.cmake @@ -280,7 +280,7 @@ log_option("CACHE_ALL_FLAG_VARS") log_option("ENABLE_COLOR") log_option("SET_LINKER") -log_decorator("=============================================================") +log_decorator("-------------------------------------------------------------") # ------------------------------------------------------------------------------ # 8) Optional: Dump ALL cache variables @@ -292,5 +292,19 @@ if(VERBOSE_TOOLCHAIN_LOG) get_property(_val CACHE "${_cv}" PROPERTY VALUE) log_debug(" [${_cv}] = ${_val}") endforeach() - log_decorator("=============================================================") -endif() \ No newline at end of file + log_decorator("-------------------------------------------------------------") +endif() + + +# ------------------------------------------------------------------------------ +# 13) Summary Report +# ------------------------------------------------------------------------------ +log_decorator("=================== BUILD SUMMARY ===========================") + +log_info("Build Type : ${CMAKE_BUILD_TYPE}") +log_info("C Compiler : ${CMAKE_C_COMPILER} (${CMAKE_C_COMPILER_VERSION})") +log_info("C++ Compiler : ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_VERSION})") +log_info("Build Shared Libs : ${BUILD_SHARED_LIBS}") +log_info("Optimization Flags : ${CMAKE_C_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}") + +log_decorator("=============================================================") diff --git a/components/open-aa-std-adaptive-autosar-libs/include/ara/core/array.h b/components/open-aa-std-adaptive-autosar-libs/include/ara/core/array.h index eecb188..23bbb9a 100644 --- a/components/open-aa-std-adaptive-autosar-libs/include/ara/core/array.h +++ b/components/open-aa-std-adaptive-autosar-libs/include/ara/core/array.h @@ -48,7 +48,7 @@ #include // For demonstration logging (std::cerr) #include // For std::terminate (to handle violations/fatal errors) -// Pull in location utilities for capturing file/line details: +/* Pull in location utilities for capturing file/line details: */ #include "ara/core/internal/location_utils.h" /********************************************************************************************************************** @@ -168,6 +168,64 @@ constexpr bool is_single_same_array_v = is_single_same_array. } // namespace detail +/********************************************************************************************************************** + * SECTION: Array Storage Base Classes + *********************************************************************************************************************/ +/*! + * \brief Base class for Array storage. + * \tparam T The type of elements. + * \tparam N The size of the array. + * \tparam B A boolean indicating whether N > 0. + * + * \details + * - Primary template handles N > 0. + */ +template 0)> +struct ArrayStorage; + +/*! + * \brief Primary template for Array storage when N > 0. + */ +template +struct ArrayStorage +{ +protected: + T data_[N]{}; + + // Variadic constructor to initialize data_ with Args... + template ...> && + detail::is_brace_initializable_array::value + >> + constexpr ArrayStorage(Args&&... args) + noexcept(std::conjunction_v...>) + : data_{std::forward(args)...} + { + // No further initialization required + } +}; + +/*! + * \brief Partial specialization for Array storage when N = 0. + */ +template +struct ArrayStorage +{ +protected: + // No storage needed for zero-sized array + constexpr ArrayStorage() noexcept = default; + + // Variadic constructor for N=0 should not accept any arguments + template > + constexpr ArrayStorage(Args&&... /*args*/) noexcept + { + // No operation needed + } +}; + /********************************************************************************************************************** * CLASS: ara::core::Array *********************************************************************************************************************/ @@ -184,10 +242,10 @@ constexpr bool is_single_same_array_v = is_single_same_array. * - Complies with [SWS_CORE_01201], which defines the API class \a ara::core::Array. * - Provides fill(), swap(), and comparison operators as required by [SWS_CORE_01241], [SWS_CORE_01242], etc. * - * \pre Typically, we expect N > 0, though zero-sized arrays can be permitted if required by the specification. + * \pre Typically, we expect N > 0, though zero-sized arrays are handled appropriately. */ template -class Array final +class Array final : private ArrayStorage { public: // ----------------------------------------------------------------------------------- @@ -238,9 +296,9 @@ class Array final >> constexpr Array(Args&&... args) noexcept(std::conjunction_v...>) - : data_{std::forward(args)...} // Initialize data_ directly with args to trigger narrowing checks + : ArrayStorage(std::forward(args)...) { - // No further initialization required; compiler handles list-initialization of data_ + // No further initialization required; base class handles data_ initialization } // ----------------------------------------------------------------------------------- @@ -311,9 +369,12 @@ class Array final "\n[ERROR] Cannot assign ara::core::Array to ara::core::Array.\n" " Ensure that both arrays have the same size in ara::core::Array.\n"); - for (std::size_t i = 0; i < N; ++i) { - data_[i] = other[i]; + if constexpr (N > 0) { + for (std::size_t i = 0; i < N; ++i) { + this->data_[i] = other[i]; + } } + // No operation needed if N == 0 return *this; } @@ -376,15 +437,26 @@ class Array final * \note If idx >= N, triggers \c detail::TriggerOutOfRangeViolation => terminates. */ constexpr auto at(size_type idx) noexcept -> reference { - if (idx >= N) { + if constexpr (N > 0) { + if (idx >= N) { + detail::TriggerOutOfRangeViolation( + "Array", + ARA_CORE_INTERNAL_FILELINE, // capture file:line from location_utils + idx, + N + ); + } + } else { + // N == 0; any access is out of range detail::TriggerOutOfRangeViolation( "Array", - ARA_CORE_INTERNAL_FILELINE, // capture file:line from location_utils + ARA_CORE_INTERNAL_FILELINE, idx, N ); } - return data_[idx]; + + return data()[idx]; } /*! @@ -394,7 +466,17 @@ class Array final * \note If idx >= N, triggers \c detail::TriggerOutOfRangeViolation => terminates. */ constexpr auto at(size_type idx) const noexcept -> const_reference { - if (idx >= N) { + if constexpr (N > 0) { + if (idx >= N) { + detail::TriggerOutOfRangeViolation( + "Array", + ARA_CORE_INTERNAL_FILELINE, + idx, + N + ); + } + } else { + // N == 0; any access is out of range detail::TriggerOutOfRangeViolation( "Array", ARA_CORE_INTERNAL_FILELINE, @@ -402,7 +484,8 @@ class Array final N ); } - return data_[idx]; + + return data()[idx]; } // ----------------------------------------------------------------------------------- @@ -412,49 +495,49 @@ class Array final /*! * \brief Returns a \e mutable reference to the first element (like std::array::front). * \return Reference to the first element. - * \note static_assert(N > 0) so this is a compile-time error if N=0. + * \note Triggers a compile-time error if N == 0. */ constexpr auto front() noexcept -> reference { static_assert(N > 0, "\n[ERROR] front() called on zero-sized Array.\n" " front() shall be called upon a non-zero sized Array in ara::core::Array.\n"); - return data_[0]; + return data()[0]; } /*! * \brief Returns a \e const reference to the first element. * \return Const reference to the first element. - * \note static_assert(N > 0) so this is a compile-time error if N=0. + * \note Triggers a compile-time error if N == 0. */ constexpr auto front() const noexcept -> const_reference { static_assert(N > 0, "\n[ERROR] front() called on zero-sized Array.\n" " front() shall be called upon a non-zero sized Array in ara::core::Array.\n"); - return data_[0]; + return data()[0]; } /*! * \brief Returns a \e mutable reference to the last element. * \return Reference to the last element. - * \note static_assert(N > 0) so this is a compile-time error if N=0. + * \note Triggers a compile-time error if N == 0. */ constexpr auto back() noexcept -> reference { static_assert(N > 0, "\n[ERROR] back() called on zero-sized Array.\n" " back() shall be called upon a non-zero sized Array in ara::core::Array.\n"); - return data_[N - 1]; + return data()[N - 1]; } /*! * \brief Returns a \e const reference to the last element. * \return Const reference to the last element. - * \note static_assert(N > 0) so this is a compile-time error if N=0. + * \note Triggers a compile-time error if N == 0. */ constexpr auto back() const noexcept -> const_reference { static_assert(N > 0, "\n[ERROR] back() called on zero-sized Array.\n" " back() shall be called upon a non-zero sized Array in ara::core::Array.\n"); - return data_[N - 1]; + return data()[N - 1]; } // ----------------------------------------------------------------------------------- @@ -466,10 +549,11 @@ class Array final * \return If N==0, returns nullptr; else &data_[0]. */ constexpr auto data() noexcept -> pointer { - if constexpr (N == 0) { + if constexpr (N > 0) { + return this->data_; + } else { return nullptr; } - return data_; } /*! @@ -477,10 +561,11 @@ class Array final * \return If N==0, returns nullptr; else &data_[0]. */ constexpr auto data() const noexcept -> const_pointer { - if constexpr (N == 0) { + if constexpr (N > 0) { + return this->data_; + } else { return nullptr; } - return data_; } // ----------------------------------------------------------------------------------- @@ -536,7 +621,11 @@ class Array final * \return Iterator to one-past-the-last element. */ constexpr auto end() noexcept -> iterator { - return data() + N; + if constexpr (N > 0) { + return data() + N; + } else { + return nullptr; + } } /*! @@ -544,7 +633,11 @@ class Array final * \return Const iterator to one-past-the-last element. */ constexpr auto end() const noexcept -> const_iterator { - return data() + N; + if constexpr (N > 0) { + return data() + N; + } else { + return nullptr; + } } /*! @@ -605,9 +698,12 @@ class Array final * \note The operation is conditionally \c noexcept if T's copy assignment is \c noexcept. */ constexpr auto fill(const T& val) noexcept(std::is_nothrow_copy_assignable::value) -> void { - for (size_type i = 0; i < N; ++i) { - data_[i] = val; + if constexpr (N > 0) { + for (std::size_t i = 0; i < N; ++i) { + this->data_[i] = val; + } } + // No operation needed if N == 0 } // ----------------------------------------------------------------------------------- @@ -620,26 +716,29 @@ class Array final * \note Uses std::swap for each element; conditionally \c noexcept if T is \c nothrow swappable. */ constexpr auto swap(Array& other) noexcept(noexcept(std::swap(std::declval(), std::declval()))) -> void { - for (size_type i = 0; i < N; ++i) { - std::swap(data_[i], other.data_[i]); + if constexpr (N > 0) { + for (std::size_t i = 0; i < N; ++i) { + std::swap(this->data_[i], other.data_[i]); + } } + // No operation needed if N == 0 } private: // ----------------------------------------------------------------------------------- - // STORAGE - // [SWS_CORE_01201] + // STORAGE ACCESSOR // ----------------------------------------------------------------------------------- - T data_[N]{}; /*!< Underlying storage for the array elements, default-initialized. */ + // *** Removed duplicate data() functions from private section *** }; + /********************************************************************************************************************** * NON-MEMBER FUNCTIONS *********************************************************************************************************************/ -// ----------------------------------------------------------------------------------- -// get (lvalue, rvalue, const) [SWS_CORE_01282], [SWS_CORE_01283], [SWS_CORE_01284] -// ----------------------------------------------------------------------------------- +/******************************************************************************************** + * get (lvalue, rvalue, const) [SWS_CORE_01282], [SWS_CORE_01283], [SWS_CORE_01284] + ********************************************************************************************/ /*! * \brief Retrieves the I-th element (mutable reference) from \c arr. * \tparam I The compile-time index. @@ -691,9 +790,9 @@ constexpr auto get(const Array& arr) noexcept -> const T& { return arr[I]; } -// ----------------------------------------------------------------------------------- -// Comparison operators [SWS_CORE_01290..01295] -// ----------------------------------------------------------------------------------- +/******************************************************************************************** + * Comparison operators [SWS_CORE_01290..01295] + ********************************************************************************************/ /*! * \brief Checks if two Arrays have \e equal content (elementwise). * @@ -802,6 +901,9 @@ auto operator>=(const Array& lhs, const Array& rhs) return !(lhs < rhs); } +/******************************************************************************************** + * swap (Non-Member Function) + ********************************************************************************************/ /*! * \brief Overload of std::swap for ara::core::Array, calls Array::swap internally. * \tparam T The type of elements stored in the arrays. diff --git a/components/open-aa-std-adaptive-autosar-libs/include/ara/core/internal/location_utils.h b/components/open-aa-std-adaptive-autosar-libs/include/ara/core/internal/location_utils.h index 42c1431..57e92b6 100644 --- a/components/open-aa-std-adaptive-autosar-libs/include/ara/core/internal/location_utils.h +++ b/components/open-aa-std-adaptive-autosar-libs/include/ara/core/internal/location_utils.h @@ -74,8 +74,8 @@ constexpr auto CutLeadingPath(const char* fullPath) noexcept -> const char* * - The final string might look like "file.cpp:123" if the path was "C:\xyz\file.cpp". */ #define ARA_CORE_INTERNAL_FILELINE \ - [] { \ - constexpr const char path_and_line[] = __FILE__ ":" ARA_CORE_LOC_STRINGIFY(__LINE__); \ + []() -> const char* { \ + static constexpr char path_and_line[] = __FILE__ ":" ARA_CORE_LOC_STRINGIFY(__LINE__); \ return ::ara::core::internal::CutLeadingPath(path_and_line); \ }()