diff options
author | Brad King <brad.king@kitware.com> | 2017-12-05 17:49:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-12-05 18:06:37 (GMT) |
commit | f74e7761a5281b54a517f1b975a33528eeaf056d (patch) | |
tree | 2084f2267c0078f6f148a9220f9605ef29277781 | |
parent | 3a81f3cc3060be86064ba2e666d30b0c358cc847 (diff) | |
download | CastXML-f74e7761a5281b54a517f1b975a33528eeaf056d.zip CastXML-f74e7761a5281b54a517f1b975a33528eeaf056d.tar.gz CastXML-f74e7761a5281b54a517f1b975a33528eeaf056d.tar.bz2 |
RunClang: Detect -std=c++17 from --castxml-cc-msvc
Updates to VS 2015 and VS 2017 added support for `-std:` flags
specifying the language standard level for MSVC. The level is reported
in the `_MSVC_LANG` preprocessor definition instead of `__cplusplus`.
Detect MSVC standard C++ level from `_MSVC_LANG`.
-rw-r--r-- | share/castxml/detect_vs.cpp | 3 | ||||
-rw-r--r-- | src/RunClang.cxx | 17 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/cc-msvc.c | 8 | ||||
-rw-r--r-- | test/expect/cmd.cc-msvc-std-c++17.stderr.txt | 1 |
5 files changed, 29 insertions, 1 deletions
diff --git a/share/castxml/detect_vs.cpp b/share/castxml/detect_vs.cpp index 130c974..2b24955 100644 --- a/share/castxml/detect_vs.cpp +++ b/share/castxml/detect_vs.cpp @@ -65,6 +65,9 @@ #ifdef _MSC_VER # pragma message(TO_DEFINE(_MSC_VER)) #endif +#ifdef _MSVC_LANG +# pragma message(TO_DEFINE(_MSVC_LANG)) +#endif #ifdef _MT # pragma message(TO_DEFINE(_MT)) #endif diff --git a/src/RunClang.cxx b/src/RunClang.cxx index de8f25a..1d4cbab 100644 --- a/src/RunClang.cxx +++ b/src/RunClang.cxx @@ -649,7 +649,22 @@ int runClang(const char* const* argBeg, const char* const* argEnd, msc_ver = 1600; } if (msc_ver >= 1900) { - args.push_back("-std=c++14"); + long msvc_lang = 0; + if (const char* l = strstr(pd.c_str(), "#define _MSVC_LANG ")) { + l += 19; + if (const char* le = strchr(l, '\n')) { + if (*(le - 1) == '\r') { + --le; + } + std::string const msvc_lang_str(l, le - l); + msvc_lang = std::strtol(msvc_lang_str.c_str(), nullptr, 10); + } + } + if (msvc_lang >= 201703L) { + args.push_back("-std=c++17"); + } else { + args.push_back("-std=c++14"); + } } else if (msc_ver >= 1600) { args.push_back("-std=c++11"); } else { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e0fbc09..016e59e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -331,6 +331,7 @@ castxml_test_cmd(cc-msvc-tgt-x86_64 --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> castxml_test_cmd(cc-msvc-std-c++98 --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> -msc=1500 ")" ${empty_cxx} "-###") castxml_test_cmd(cc-msvc-std-c++11 --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> -msc=1600 ")" ${empty_cxx} "-###") castxml_test_cmd(cc-msvc-std-c++14 --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> -msc=1900 ")" ${empty_cxx} "-###") +castxml_test_cmd(cc-msvc-std-c++17 --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> -msc=1900 -msvc_lang=201703L ")" ${empty_cxx} "-###") castxml_test_cmd(cc-msvc-std-explicit --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> -msc=1500 ")" -std=gnu++14 ${empty_cxx} "-###") castxml_test_cmd(cc-msvc-builtin-1800-E --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> -msc=1800 ")" ${empty_cxx} -E -dM) castxml_test_cmd(cc-msvc-builtin-1900-E --castxml-cc-msvc "(" $<TARGET_FILE:cc-msvc> -msc=1900 ")" ${empty_cxx} -E -dM) diff --git a/test/cc-msvc.c b/test/cc-msvc.c index 10afc63..45feff8 100644 --- a/test/cc-msvc.c +++ b/test/cc-msvc.c @@ -5,12 +5,15 @@ int main(int argc, const char* argv[]) { int cpp = 0; const char* msc_ver = "1600"; + const char* msvc_lang = 0; int i; for (i = 1; i < argc; ++i) { if (strncmp(argv[i], "--cc-define=", 12) == 0) { fprintf(stdout, "\n#define %s 1", argv[i]+12); } else if (strncmp(argv[i], "-msc=", 5) == 0) { msc_ver = argv[i]+5; + } else if (strncmp(argv[i], "-msvc_lang=", 8) == 0) { + msvc_lang = argv[i]+11; } else if (strstr(argv[i], ".cpp")) { cpp = 1; } @@ -26,6 +29,11 @@ int main(int argc, const char* argv[]) fprintf(stdout, "#define _MSC_VER %s\n", msc_ver ); + if(msvc_lang) { + fprintf(stdout, + "#define _MSVC_LANG %s\n", msvc_lang + ); + } fprintf(stdout, "#define __has_include(x) x\n" "#define __has_include_next(x) x\n" diff --git a/test/expect/cmd.cc-msvc-std-c++17.stderr.txt b/test/expect/cmd.cc-msvc-std-c++17.stderr.txt new file mode 100644 index 0000000..e5f5dd6 --- /dev/null +++ b/test/expect/cmd.cc-msvc-std-c++17.stderr.txt @@ -0,0 +1 @@ +"clang" .* "-std=c\+\+17" |