forked from qt-creator/qt-creator
Clang: Add conditions for adding exceptions flag
For GCC it can be deduced from the compiler flags, so no correction is
needed.
For MSVC it can be deduced from the detected defines.
Amends 26693e8212
.
Change-Id: Ie4850f328a2afdb3e5158c58f8c30a2644d9c592
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
6d51955451
commit
a408bcfd3d
@@ -35,6 +35,7 @@
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmacro.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/cpplanguage_details.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
@@ -137,7 +138,7 @@ QStringList CompilerOptionsBuilder::build(ProjectFile::Kind fileKind,
|
||||
addTargetTriple();
|
||||
updateFileLanguage(fileKind);
|
||||
addLanguageVersionAndExtensions();
|
||||
enableExceptions();
|
||||
addMsvcExceptions();
|
||||
|
||||
addPrecompiledHeaderOptions(usePrecompiledHeaders);
|
||||
addProjectConfigFileInclude();
|
||||
@@ -273,6 +274,17 @@ void CompilerOptionsBuilder::addCompilerFlags()
|
||||
add(m_compilerFlags.flags);
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::addMsvcExceptions()
|
||||
{
|
||||
if (!m_clStyle)
|
||||
return;
|
||||
if (Utils::anyOf(m_projectPart.toolChainMacros, [](const ProjectExplorer::Macro ¯o) {
|
||||
return macro.key == "_CPPUNWIND";
|
||||
})) {
|
||||
enableExceptions();
|
||||
}
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::enableExceptions()
|
||||
{
|
||||
// With "--driver-mode=cl" exceptions are disabled (clang 8).
|
||||
|
@@ -69,6 +69,7 @@ public:
|
||||
void addExtraCodeModelFlags();
|
||||
void addPicIfCompilerFlagsContainsIt();
|
||||
void addCompilerFlags();
|
||||
void addMsvcExceptions();
|
||||
void enableExceptions();
|
||||
void insertWrappedQtHeaders();
|
||||
void insertWrappedMingwHeaders();
|
||||
|
@@ -650,8 +650,6 @@ TEST_F(CompilerOptionsBuilder, BuildAllOptions)
|
||||
"-x",
|
||||
"c++",
|
||||
"-std=c++17",
|
||||
"-fcxx-exceptions",
|
||||
"-fexceptions",
|
||||
"-DprojectFoo=projectBar",
|
||||
"-I", IsPartOfHeader("wrappedQtHeaders"),
|
||||
"-I", IsPartOfHeader(toNative("wrappedQtHeaders/QtCore").toStdString()),
|
||||
@@ -674,6 +672,44 @@ TEST_F(CompilerOptionsBuilder, BuildAllOptionsCl)
|
||||
|
||||
compilerOptionsBuilder.build(ProjectFile::CXXSource, CppTools::UsePrecompiledHeaders::No);
|
||||
|
||||
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||
ElementsAre("-nostdinc",
|
||||
"-nostdinc++",
|
||||
"--driver-mode=cl",
|
||||
"/Zs",
|
||||
"-m64",
|
||||
"--target=x86_64-apple-darwin10",
|
||||
"/TP",
|
||||
"/std:c++17",
|
||||
"-fms-compatibility-version=19.00",
|
||||
"-DprojectFoo=projectBar",
|
||||
"-D__FUNCSIG__=\"\"",
|
||||
"-D__FUNCTION__=\"\"",
|
||||
"-D__FUNCDNAME__=\"\"",
|
||||
"-I", IsPartOfHeader("wrappedQtHeaders"),
|
||||
"-I", IsPartOfHeader(toNative("wrappedQtHeaders/QtCore").toStdString()),
|
||||
"-I", toNative("/tmp/path"),
|
||||
"-I", toNative("/tmp/system_path"),
|
||||
"/clang:-isystem",
|
||||
"/clang:" + toNative(CLANG_RESOURCE_DIR ""),
|
||||
"/clang:-isystem",
|
||||
"/clang:" + toNative("/tmp/builtin_path")));
|
||||
}
|
||||
|
||||
TEST_F(CompilerOptionsBuilder, BuildAllOptionsClWithExceptions)
|
||||
{
|
||||
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
||||
projectPart.toolChainMacros.append(ProjectExplorer::Macro{"_CPPUNWIND", "1"});
|
||||
CppTools::CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
||||
CppTools::UseSystemHeader::No,
|
||||
CppTools::UseTweakedHeaderPaths::Yes,
|
||||
CppTools::UseLanguageDefines::No,
|
||||
CppTools::UseBuildSystemWarnings::No,
|
||||
"dummy_version",
|
||||
"");
|
||||
|
||||
compilerOptionsBuilder.build(ProjectFile::CXXSource, CppTools::UsePrecompiledHeaders::No);
|
||||
|
||||
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||
ElementsAre("-nostdinc",
|
||||
"-nostdinc++",
|
||||
|
Reference in New Issue
Block a user