Skip to content

Commit 879d97d

Browse files
committed
core/span: back-port C++20/26 helpers with the test cases
1 parent f6a33be commit 879d97d

File tree

18 files changed

+3835
-220
lines changed

18 files changed

+3835
-220
lines changed

CMake/CMakeConfig/clang21_linux_aarch64_debug.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
5757
# and are optimized for aarch64 by using -march=armv8-a.
5858
#=======================================================================
5959
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
60-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes -Wstrict-aliasing=2 \
60+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes -Wstrict-aliasing=2 \
6161
-Wundef -Wredundant-decls -Wcast-align -Wformat=2 -Wfloat-equal \
6262
-fno-common -march=armv8-a -flto -fstack-protector-strong \
6363
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C Compiler Flags")
@@ -84,7 +84,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
8484
#=======================================================================
8585
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion \
8686
-Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations \
87-
-Werror -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
87+
-Werror -Wstrict-overflow=2 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
8888
-Wcast-align -Wformat=2 -Wfloat-equal -fno-exceptions -fno-rtti \
8989
-fno-common -march=armv8-a -flto -fstack-protector-strong \
9090
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C++ Compiler Flags")

CMake/CMakeConfig/clang21_linux_aarch64_release.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
5757
# and are optimized for aarch64 by using -march=armv8-a.
5858
#=======================================================================
5959
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
60-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes -Wstrict-aliasing=2 \
60+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes -Wstrict-aliasing=2 \
6161
-Wundef -Wredundant-decls -Wcast-align -Wformat=2 -Wfloat-equal \
6262
-fno-common -march=armv8-a -flto -fstack-protector-strong \
6363
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C Compiler Flags")
@@ -84,7 +84,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
8484
#=======================================================================
8585
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion \
8686
-Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations \
87-
-Werror -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
87+
-Werror -Wstrict-overflow=2 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
8888
-Wcast-align -Wformat=2 -Wfloat-equal -fno-exceptions -fno-rtti \
8989
-fno-common -march=armv8-a -flto -fstack-protector-strong \
9090
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C++ Compiler Flags")

CMake/CMakeConfig/clang21_linux_x86_64_release.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
7272
#
7373
# Added Flags:
7474
# -Werror: Treat all warnings as errors.
75-
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
75+
# -Wstrict-overflow=2: Warn about cases where the compiler assumes that signed overflow does not occur.
7676
# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration.
7777
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
7878
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
@@ -87,7 +87,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
8787
# -D_FORTIFY_SOURCE=2: Enable additional compile-time and run-time checks for buffer overflows.
8888
#=======================================================================
8989
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
90-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes \
90+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes \
9191
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
9292
-Wcast-align -Wformat=2 -Wfloat-equal \
9393
-fno-common -march=native -flto -fstack-protector-strong \
@@ -136,7 +136,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
136136
#
137137
# Added Flags:
138138
# -Werror: Treat all warnings as errors.
139-
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
139+
# -Wstrict-overflow=2: Warn about cases where the compiler assumes that signed overflow does not occur.
140140
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
141141
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
142142
# -Wredundant-decls: Warn about redundant declarations.
@@ -153,7 +153,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
153153
#=======================================================================
154154
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \
155155
-pedantic -Wshadow -Wno-error=deprecated-declarations \
156-
-Werror -Wstrict-overflow=5 \
156+
-Werror -Wstrict-overflow=2 \
157157
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
158158
-Wcast-align -Wformat=2 -Wfloat-equal \
159159
-fno-exceptions -fno-rtti -fno-common -march=native -flto -fstack-protector-strong \

CMake/CMakeConfig/gcc11_linux_aarch64_release.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
5757
# and are optimized for aarch64 by using -march=armv8-a.
5858
#=======================================================================
5959
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
60-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes -Wstrict-aliasing=2 \
60+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes -Wstrict-aliasing=2 \
6161
-Wundef -Wredundant-decls -Wcast-align -Wformat=2 -Wfloat-equal \
6262
-fno-common -march=armv8-a -flto -fstack-protector-strong \
6363
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C Compiler Flags")
@@ -84,7 +84,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
8484
#=======================================================================
8585
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion \
8686
-Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations \
87-
-Werror -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
87+
-Werror -Wstrict-overflow=2 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
8888
-Wcast-align -Wformat=2 -Wfloat-equal -fno-exceptions -fno-rtti \
8989
-fno-common -march=armv8-a -flto -fstack-protector-strong \
9090
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C++ Compiler Flags")

CMake/CMakeConfig/gcc11_linux_x86_64_release.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
7272
#
7373
# Added Flags:
7474
# -Werror: Treat all warnings as errors.
75-
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
75+
# -Wstrict-overflow=2: Warn about cases where the compiler assumes that signed overflow does not occur.
7676
# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration.
7777
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
7878
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
@@ -87,7 +87,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
8787
# -D_FORTIFY_SOURCE=2: Enable additional compile-time and run-time checks for buffer overflows.
8888
#=======================================================================
8989
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
90-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes \
90+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes \
9191
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
9292
-Wcast-align -Wformat=2 -Wfloat-equal \
9393
-fno-common -march=native -flto -fstack-protector-strong \
@@ -136,7 +136,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
136136
#
137137
# Added Flags:
138138
# -Werror: Treat all warnings as errors.
139-
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
139+
# -Wstrict-overflow=2: Warn about cases where the compiler assumes that signed overflow does not occur.
140140
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
141141
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
142142
# -Wredundant-decls: Warn about redundant declarations.
@@ -153,7 +153,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
153153
#=======================================================================
154154
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \
155155
-pedantic -Wshadow -Wno-error=deprecated-declarations \
156-
-Werror -Wstrict-overflow=5 \
156+
-Werror -Wstrict-overflow=2 \
157157
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
158158
-Wcast-align -Wformat=2 -Wfloat-equal \
159159
-fno-exceptions -fno-rtti -fno-common -march=native -flto -fstack-protector-strong \

CMake/CMakeConfig/gcc13_linux_aarch64_release.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
5757
# and are optimized for aarch64 by using -march=armv8-a.
5858
#=======================================================================
5959
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
60-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes -Wstrict-aliasing=2 \
60+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes -Wstrict-aliasing=2 \
6161
-Wundef -Wredundant-decls -Wcast-align -Wformat=2 -Wfloat-equal \
6262
-fno-common -march=armv8-a -flto -fstack-protector-strong \
6363
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C Compiler Flags")
@@ -84,7 +84,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
8484
#=======================================================================
8585
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion \
8686
-Wold-style-cast -pedantic -Wshadow -Wno-error=deprecated-declarations \
87-
-Werror -Wstrict-overflow=5 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
87+
-Werror -Wstrict-overflow=2 -Wstrict-aliasing=2 -Wundef -Wredundant-decls \
8888
-Wcast-align -Wformat=2 -Wfloat-equal -fno-exceptions -fno-rtti \
8989
-fno-common -march=armv8-a -flto -fstack-protector-strong \
9090
-D_FORTIFY_SOURCE=2" CACHE STRING "Initial C++ Compiler Flags")

CMake/CMakeConfig/gcc13_linux_x86_64_release.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
7272
#
7373
# Added Flags:
7474
# -Werror: Treat all warnings as errors.
75-
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
75+
# -Wstrict-overflow=2: Warn about cases where the compiler assumes that signed overflow does not occur.
7676
# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype declaration.
7777
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
7878
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
@@ -87,7 +87,7 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE CACHE BOOL "Enable Link Time Optimiz
8787
# -D_FORTIFY_SOURCE=2: Enable additional compile-time and run-time checks for buffer overflows.
8888
#=======================================================================
8989
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow \
90-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes \
90+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes \
9191
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
9292
-Wcast-align -Wformat=2 -Wfloat-equal \
9393
-fno-common -march=native -flto -fstack-protector-strong \
@@ -136,7 +136,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
136136
#
137137
# Added Flags:
138138
# -Werror: Treat all warnings as errors.
139-
# -Wstrict-overflow=5: Warn about cases where the compiler assumes that signed overflow does not occur.
139+
# -Wstrict-overflow=2: Warn about cases where the compiler assumes that signed overflow does not occur.
140140
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
141141
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
142142
# -Wredundant-decls: Warn about redundant declarations.
@@ -153,7 +153,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
153153
#=======================================================================
154154
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \
155155
-pedantic -Wshadow -Wno-error=deprecated-declarations \
156-
-Werror -Wstrict-overflow=5 \
156+
-Werror -Wstrict-overflow=2 \
157157
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
158158
-Wcast-align -Wformat=2 -Wfloat-equal \
159159
-fno-exceptions -fno-rtti -fno-common -march=native -flto -fstack-protector-strong \

CMake/CMakeConfig/qcc12_qnx800_aarch64_release.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
8080
#
8181
# Added Flags:
8282
# -Werror: Treat all warnings as errors.
83-
# -Wstrict-overflow=5: Warn when the compiler assumes signed overflow does not occur.
83+
# -Wstrict-overflow=2: Warn when the compiler assumes signed overflow does not occur.
8484
# -Wmissing-prototypes: Warn if a global function is defined without a previous prototype.
8585
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
8686
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
@@ -92,7 +92,7 @@ set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries")
9292
# -mcpu=generic: Optimize for generic AArch64 architecture.
9393
#=======================================================================
9494
set(CMAKE_C_FLAGS_INIT "-Wall -Wextra -Wconversion -pedantic -Wshadow -D_QNX_SOURCE \
95-
-Werror -Wstrict-overflow=5 -Wmissing-prototypes \
95+
-Werror -Wstrict-overflow=2 -Wmissing-prototypes \
9696
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
9797
-Wcast-align -Wformat=2 -Wfloat-equal \
9898
-fno-common -mcpu=generic" CACHE STRING "Initial C Compiler Flags")
@@ -138,7 +138,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
138138
#
139139
# Added Flags:
140140
# -Werror: Treat all warnings as errors.
141-
# -Wstrict-overflow=5: Warn when the compiler assumes signed overflow does not occur.
141+
# -Wstrict-overflow=2: Warn when the compiler assumes signed overflow does not occur.
142142
# -Wstrict-aliasing=2: Enforce strict aliasing rules.
143143
# -Wundef: Warn if an undefined identifier is evaluated in an `#if` directive.
144144
# -Wredundant-decls: Warn about redundant declarations.
@@ -151,7 +151,7 @@ set(CMAKE_C_FLAGS_RELEASEWITHO2_INIT "-O2 -DNDEBUG" CACHE STRING "C Compiler Fla
151151
#=======================================================================
152152
set(CMAKE_CXX_FLAGS_INIT "-Wall -Wextra -Wnon-virtual-dtor -Wconversion -Wold-style-cast \
153153
-pedantic -Wshadow -Wno-error=deprecated-declarations -v -D_QNX_SOURCE \
154-
-Werror -Wstrict-overflow=5 \
154+
-Werror -Wstrict-overflow=2 \
155155
-Wstrict-aliasing=2 -Wundef -Wredundant-decls \
156156
-Wcast-align -Wformat=2 -Wfloat-equal \
157157
-fno-exceptions -fno-rtti -mcpu=generic" CACHE STRING "Initial C++ Compiler Flags")

components/open-aa-std-adaptive-autosar-libs/CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ target_link_libraries(ara_core_array INTERFACE
5858
)
5959

6060
# ----------------------------------------------------------------------
61-
# 3) ARA::CORE::Byte
61+
# 4) ARA::CORE::BYTE
6262
# ----------------------------------------------------------------------
6363
add_library(ara_core_byte INTERFACE)
6464
add_library(ara::core::byte ALIAS ara_core_byte)
@@ -75,7 +75,24 @@ target_link_libraries(ara_core_byte INTERFACE
7575
)
7676

7777
# ----------------------------------------------------------------------
78-
# 3) Installation of Headers
78+
# 5) ARA::CORE::SPAN
79+
# ----------------------------------------------------------------------
80+
add_library(ara_core_span INTERFACE)
81+
add_library(ara::core::span ALIAS ara_core_span)
82+
83+
# Provide include directories for ara::core::span
84+
target_include_directories(ara_core_span INTERFACE
85+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> # Path to span headers during build
86+
$<INSTALL_INTERFACE:include> # Path to span headers after installation
87+
)
88+
89+
# link INTERFACE libraries
90+
target_link_libraries(ara_core_span INTERFACE
91+
ara::core::violation
92+
)
93+
94+
# ----------------------------------------------------------------------
95+
# 6) Installation of Headers
7996
# ----------------------------------------------------------------------
8097
# Install the ara/core headers, including array.h and internal headers
8198
install(DIRECTORY

components/open-aa-std-adaptive-autosar-libs/include/ara/core/array.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include <cstring> // For std::memcpy, std::memset
4646
#include <iterator> // For std::reverse_iterator
4747

48-
#include "ara/core/byte.h" // For ara::core::Byte type
4948
#include "ara/core/internal/utility.h" // For utility functions and traits
5049
#include "ara/core/internal/location_utils.h" // For capturing file/line details
5150
#include "ara/core/internal/violation_handler.h" // To Trigger the violation
@@ -1167,7 +1166,7 @@ constexpr auto operator<(const Array<T, N>& lhs, const Array<T, N>& rhs)
11671166
return std::memcmp(lhs.data(), rhs.data(), N) < 0;
11681167
}
11691168

1170-
return detail::lex_compare(lhs.begin(), lhs.end(),
1169+
return detail::constexpr_lexicographical_compare(lhs.begin(), lhs.end(),
11711170
rhs.begin(), rhs.end());
11721171
}
11731172

@@ -1197,7 +1196,7 @@ constexpr auto operator<(const Array<T, N>& lhs, const Array<T, N>& rhs)
11971196
"\n[ERROR] in ara::core::Array: The type T's operator< must be marked 'noexcept' when exceptions are disabled.\n");
11981197
#endif
11991198

1200-
return detail::lex_compare(lhs.begin(), lhs.end(),
1199+
return detail::constexpr_lexicographical_compare(lhs.begin(), lhs.end(),
12011200
rhs.begin(), rhs.end());
12021201
}
12031202

0 commit comments

Comments
 (0)