llvm-project/clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp
faisal vali 5bdd5d064d Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32
See issue https://github.com/llvm/llvm-project/issues/62594

This code does not work on win32:

  auto lstatic = []()  static  { return 0;  };
  int (*f2)(void) = lstatic;

Since a calling convention such as CC_X86ThisCall can rightly interfere with the implicit pointer to function conversion if erroneously marked on a static function, the fix entails checking the 'static' specifier on the lambda declarator prior to assigning it a calling convention of an non-static member (which pre-c++23 made sense).
2023-09-16 13:29:59 -05:00

34 lines
794 B
C++

// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s
namespace ns1 {
auto lstatic = []() static { return 3; };
int (*f2)(void) = lstatic;
}
namespace ns1_1 {
auto lstatic = []() static consteval //expected-error{{cannot take address of consteval call}} \
expected-note {{declared here}}
{ return 3; };
// FIXME: the above error should indicate that it was triggered below.
int (*f2)(void) = lstatic;
}
namespace ns2 {
auto lstatic = []() static { return 3; };
constexpr int (*f2)(void) = lstatic;
static_assert(lstatic() == f2());
}
namespace ns3 {
void main() {
static int x = 10;
auto L = []() static { return x; };
}
}