Skip to content

C11 _Atomic causes cpp_thread_test to fail to compile as C++11 #5937

Description

@r-mammoto

While building the cpp_thread_test included in the OpenBLAS repository, we encountered a compilation error.

The issue appears to have been introduced by the following merge commit:

commit 8f0b0333ba0e1b8e185017112c2e760f5e616fce
Merge pull request #5876 from kumaraditya303/openmp
fix thread safety and data races of openmp backend

The cpp_thread_test/Makefile compiles dgemv_thread_safety.cpp using $(CXX) with -std=c++11. In our environment, CXX is set to g++, so the file is compiled with g++ -std=c++11.

During compilation, dgemv_thread_safety.cpp includes common.h, and the following code produces an error:

atomic_store((volatile _Atomic BLASULONG *)address, (BLASULONG)0);

The error messages are as follows:

../common.h:595:26: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
  595 |   atomic_store((volatile _Atomic BLASULONG *)address, (BLASULONG)0);
      |                          ^~~~~~~
../common.h:595:17: error: expected primary-expression before ‘volatile’
  595 |   atomic_store((volatile _Atomic BLASULONG *)address, (BLASULONG)0);
      |                 ^~~~~~~~
../common.h:595:17: error: expected ‘)’ before ‘volatile’
  595 |   atomic_store((volatile _Atomic BLASULONG *)address, (BLASULONG)0);
      |                ~^~~~~~~~
make: *** [Makefile:7: dgemv_tester] Error 1

During the OpenBLAS configuration step, the C compiler specified by CC is used to check for C11 atomic support. If the check succeeds, HAVE_C11 is defined in the generated config.h.

Because common.h includes this config.h, HAVE_C11 remains defined when cpp_thread_test is later compiled as C++11. This causes common.h to select the C11 atomic implementation, which contains the following cast:

(volatile _Atomic BLASULONG *)address

Although _Atomic is valid in C11, this type syntax is not valid in C++11. Therefore, the C++ compiler cannot parse the cast as a valid type, and the cpp_thread_test build fails.

We would appreciate the maintainers' thoughts on this issue and whether a fix could be considered to preserve compatibility with C++11 compilers.

If additional build logs, compiler information, or the generated config.h would be helpful, we would be happy to provide them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions