Skip to content

Commit

Permalink
Fix C++ portability issue with using CMPLX (#24211)
Browse files Browse the repository at this point in the history
[reviewed by @mppf]

Though compiling PR #24184 with a back-end C++ compiler worked on my
laptop and [redacted], it caused problems with other C++ compilers, like
g++ (SUSE Linux) 7.5.0 on [redacted] and some of our other nightly
testing configurations.

At present, it's somewhat circumstantial that we compile this code with
a C++ compiler at all: It only happens when compiling our qio re2 shim
code, and that code doesn't rely on these tuple-to-complex conversion
routines anyway. As a result, what I've done here is to beef up my
#ifndef to skip over the new preferred path of code when we're compiling
for C++ to be safe, and on the assumption that it doesn't really matter
anyway (won't be called); and even if that changes in the future, the
fallback paths from #24184 ought to work...

(As potentiall future work, we could also refactor our header files so
that the re2 shim only gets definitions that it truly needs, which
probably would involve forking some portions of chpltypes.h out of it
and into another header. I started into this as part of #24184 before
deciding it was overkill for that PR).
  • Loading branch information
bradcray committed Jan 18, 2024
2 parents 9a2eaa4 + f249b95 commit 774462d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions runtime/include/chpltypes.h
Expand Up @@ -255,7 +255,11 @@ typedef struct chpl_main_argument_s {
} chpl_main_argument;

static inline _complex128 _chpl_complex128(_real64 re, _real64 im) {
#ifdef CMPLX
// though CMPLX works for some C++ compilers, it doesn't work for all in our
// test environments, so dodge it to be safe; Currently, we only compile
// this header using a C++ compiler when compiling our re2 stubs, which
// don't seem to use this routine anyway.
#if defined(CMPLX) && !defined(__cplusplus)
return CMPLX(re, im);
#else
#ifndef CHPL_DONT_USE_CMPLX_PTR_ALIASING
Expand All @@ -273,7 +277,11 @@ static inline _complex128 _chpl_complex128(_real64 re, _real64 im) {
}

static inline _complex64 _chpl_complex64(_real32 re, _real32 im) {
#ifdef CMPLXF
// though CMPLXF works for some C++ compilers, it doesn't work for all in our
// test environments, so dodge it to be safe; Currently, we only compile
// this header using a C++ compiler when compiling our re2 stubs, which
// don't seem to use this routine anyway.
#if defined(CMPLX) && !defined(__cplusplus)
return CMPLXF(re, im);
#else
#ifndef CHPL_DONT_USE_CMPLX_PTR_ALIASING
Expand Down

0 comments on commit 774462d

Please sign in to comment.