Skip to content

Commit 76a43cc

Browse files
marsupialsftnight
authored andcommitted
Don’t change the C++ version from underneath clang, tell it what is desired.
1 parent 1abc653 commit 76a43cc

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

lib/Interpreter/CIFactory.cpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,6 @@ namespace {
398398
Opts.MathErrno = 0;
399399
#endif
400400

401-
// C++11 is turned on if cling is built with C++11: it's an interpreter;
402-
// cross-language compilation doesn't make sense.
403-
404-
if (Opts.CPlusPlus) {
405-
switch (CxxStdCompiledWith()) {
406-
case 17: Opts.CPlusPlus1z = 1; // intentional fall-through
407-
case 14: Opts.CPlusPlus14 = 1; // intentional fall-through
408-
case 11: Opts.CPlusPlus11 = 1; break;
409-
default: break;
410-
}
411-
}
412-
413401
#ifdef _REENTRANT
414402
Opts.POSIXThreads = 1;
415403
#endif
@@ -418,7 +406,7 @@ namespace {
418406
#endif
419407

420408
if (CompilerOpts.DefaultLanguage(Opts)) {
421-
#ifdef __STRICT_ANSI__ || defined(LLVM_ON_WIN32)
409+
#ifdef __STRICT_ANSI__
422410
Opts.GNUMode = 0;
423411
#else
424412
Opts.GNUMode = 1;
@@ -644,6 +632,17 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
644632
PreprocessorOptions& PPOpts = CI->getInvocation().getPreprocessorOpts();
645633
SetPreprocessorFromBinary(PPOpts);
646634

635+
// Sanity check that clang delivered the language standard requested
636+
const auto& LangOpts = CI->getLangOpts();
637+
if (CompilerOpts.DefaultLanguage(LangOpts)) {
638+
switch (CxxStdCompiledWith()) {
639+
case 17: assert(LangOpts.CPlusPlus1z && "Language version mismatch");
640+
case 14: assert(LangOpts.CPlusPlus14 && "Language version mismatch");
641+
case 11: assert(LangOpts.CPlusPlus11 && "Language version mismatch");
642+
default: break;
643+
}
644+
}
645+
647646
PPOpts.addMacroDef("__CLING__");
648647
if (CI->getLangOpts().CPlusPlus11 == 1)
649648
PPOpts.addMacroDef("__CLING__CXX11");
@@ -733,6 +732,19 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
733732
// We do C++ by default; append right after argv[0] if no "-x" given
734733
argvCompile.push_back("-x");
735734
argvCompile.push_back( "c++");
735+
736+
if (!COpts.StdVersion) {
737+
// By default, set the standard to what cling was compiled with.
738+
// clang::driver::Compilation will do various things while initializing
739+
// and by enforcing the std version now cling is telling clang what to
740+
// do, rather than after clang has dedcuded a default.
741+
switch (CxxStdCompiledWith()) {
742+
case 17: argvCompile.emplace_back("-std=c++1z"); break;
743+
case 14: argvCompile.emplace_back("-std=c++14"); break;
744+
case 11: argvCompile.emplace_back("-std=c++11"); break;
745+
default: llvm_unreachable("Unrecognized C++ version");
746+
}
747+
}
736748
}
737749
// argv[0] already inserted, get the rest
738750
argvCompile.insert(argvCompile.end(), argv+1, argv + argc);

0 commit comments

Comments
 (0)