[flang-commits] [PATCH] D83397: [flang] Replace uses of _Complex with std::complex

David Truby via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Jul 9 02:02:07 PDT 2020


DavidTruby added a comment.

I would actually say this is more serious than just a warning (although clang only has it as a warning for various reasons). 
_Complex is //**not a keyword that exists in C++**//, so this code is non-conformant. It also isn't implemented in MSVC which is a compiler we should try to support as the rest of LLVM does.
It's also just less ergonomic to use than `std::complex` and they are guaranteed to be layout compatible, so if we need to call into/out of C the following still works:

  // file.cpp
  #include <complex>
  extern "C" float real_part(std::complex<float> c) {
    return c.real();
  }
  
  // file.c
  #include <stdio.h>
  #include <complex.h>
  extern float real_part(float _Complex c);
  
  int main()
  {
    float _Complex c = 1+2*I;
    printf("%f\n", real_part(c));
  }

This isn't accidental; the C++ standard guarantees that this works.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83397/new/

https://reviews.llvm.org/D83397





More information about the flang-commits mailing list