https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108618
--- Comment #5 from Kyle Shores <kyle.shores44 at gmail dot com> ---
New C++ source file:
```
#include <string_view>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <ISO_Fortran_binding.h>
extern "C" {
void Finit(void);
void get_names( CFI_cdesc_t * );
}
std::vector<std::string_view> extract_names(CFI_cdesc_t* names){
std::vector<std::string_view> vs;
for (int i = 0; i < names->dim[0].extent; i++) {
// determine the length of the string up to the first whitespace character
char* addr = (char *)(names->base_addr) + i * names->elem_len;
char* first_space = strchr(addr, ' ');
size_t strlen = first_space - addr;
vs.push_back(std::string_view(addr).substr(0, strlen));
}
return vs;
}
int main(){
CFI_CDESC_T(1) names;
std::cout << names.version << std::endl;
get_names((CFI_cdesc_t *)&names);
std::cout << names.version << std::endl;
std::vector<std::string_view> vs = extract_names((CFI_cdesc_t *)&names);
for(const auto& elem : vs)
{
std::cout << elem << std::endl;
}
}
```
Makefile:
```
CXX=g++-12
FC=gfortran
CXX_FLAGS=-c -g -O0 -fprofile-arcs -ftest-coverage -fprofile-abs-path
FORT_FLAGS=-c -g -O0 -fprofile-arcs -ftest-coverage -fcheck=bounds,do,pointer
-ffpe-trap=zero,overflow,invalid -fprofile-abs-path
all: cpp fort
${CXX} -o bad_version test.o fortran_strings.o -lgcov -lgfortran
cpp:
${CXX} ${CXX_FLAGS} test.cpp
fort:
${FC} ${FORT_FLAGS} fortran_strings.F90
```
Hope that helps