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
Hi,

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:

SET(CMAKE_REQUIRED_FLAGS "-std=c++14")
check_cxx_symbol_exists("std::literals::string_literals::operator\"\"s(
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);
#endif
  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)
{
  (void)argv;
#ifndef std::literals::string_literals::operator""s(const char*,
std::size_t)
  return ((int*)(&std::literals::string_literals::operator""s(const
char*, std::size_t)))[argc];
#else
  (void)argc;
  return 0;
#endif
}

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

With regards,
Martijn Otto
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

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

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake