check_cxx_symbol_exists for std::literals works in one project, not in another

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

check_cxx_symbol_exists for std::literals works in one project, not in another

CMake mailing list

I'm struggling to understand the following behaviour. I need to test
whether std::literals is available in my project, for which I have the
following test:

const char*, std::size_t)" "string" HAVE_STD_LITERALS)

I then use the resulting HAVE_STD_LITERALS to configure an include
file. In one project this works well, in another it does not. The
project where it does work generates the following test file:

#include <string>

int main() {
#ifndef std::literals::string_literals::operator""s
  const char* arg0;
  std::size_t arg1;
  (void)std::literals::string_literals::operator""s(arg0, arg1);
  return 0;

This compiles with only a warning about extra tokens after the #ifndef
directive. In another project I try to use the same and it never
detects support, because it generates different test-code, that doesn't
compile at all:

/* */
#include <string>

int main(int argc, char** argv)
#ifndef std::literals::string_literals::operator""s(const char*,
  return ((int*)(&std::literals::string_literals::operator""s(const
char*, std::size_t)))[argc];
  return 0;

Can anybody explain why different code is generated and how I can avoid
generating this incorrect code?

With regards,
Martijn Otto

Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: