Skip to content

[OpenMP] OpenMP atomic compare fails when including <array> with using namespace std; #141085

@jhuber6

Description

@jhuber6

The following code causes a compilation failure only when using namespace std;. https://godbolt.org/z/adKe7x84c.

using namespace std;

#include <array>

template<typename T>
T atomicMin(T* acc, T value)
{
  T old;
#pragma omp atomic capture compare
  {
    old = *acc;
    if (value < *acc)
    {
      *acc = value;
    }
  }
  return old;
}
$ clang++ main.cpp -fopenmp
main.cpp:1:17: warning: using directive refers to implicitly-defined namespace 'std'
    1 | using namespace std;
      |                 ^
main.cpp:12:15: error: the statement for 'atomic compare capture' must be a compound statement of form '{v = x; cond-up-stmt}', ''{cond-up-stmt v = x;}', '{if(x == e) {x = d;} else {v = x;}}', '{r = x == e; if(r) {x = d;}}', or '{r = x == e; if(r) {x = d;} else {v = x;}}', where 'cond-update-stmt' can have one of the following forms: 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}', or 'if(e == x) {x = d;}' where 'x', 'r', and 'v' are lvalue expressions with scalar type, 'expr', 'e', and 'd' are expressions with scalar type, and 'ordop' is one of '<' or '>'
   12 |     if (value < *acc)
      |         ~~~~~~^~~~~~
main.cpp:12:15: note: expect binary operator in conditional expression
   12 |     if (value < *acc)
      |         ~~~~~~^~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"clang:openmpOpenMP related changes to Clang

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions