0

In the following C++ program:

#include <utility>
#include <cmath>

extern "C" int printf(const char*,...);

std::pair<double, double> sincos(double s) {
  return {std::sin(s), std::cos(s)};
}

void g(double a, double b) {
   printf("sin(a)=%f; cos(b)=%f\n", a, b);
}

auto [a,b] = sincos(30);

if (a < b)   // <---- HERE
  g(a,b);

int main() {

}

An if statement appears at namespace scope.

This seems to not be allowed by the standard C++ grammar (or is it?), but clang accepts it:

https://godbolt.org/z/ET5Gv8Ebf

Is this an extension? If so, is it documented somewhere?

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319

0 Answers0